Test02.java 695 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * ClassName: Test02
  3. *
  4. * @Author 爱扣钉-陈晨
  5. * @Create 2023/11/4 10:40
  6. * @Version 1.0
  7. */
  8. public class Test02 {
  9. public static void main(String[] args) {
  10. //随机数
  11. double random = Math.random();
  12. //0-1 小数数字
  13. System.out.println(random);
  14. //0 - 100
  15. double v = random * 100;
  16. System.out.println(v);
  17. //转换
  18. int i = (int) v;
  19. System.out.println(i);
  20. // 50 - 100
  21. // 0-50 + 50 ;
  22. int i1 = (int) (Math.random() * 50) + 50; // 0-49
  23. System.out.println(i1);
  24. // a - b;
  25. // (int) (Math.random() * a - b) + a
  26. }
  27. }