- 直接调用,不用导包
- Math.random() [0.0,1.0) 随机小数
- [min,max) Math.random()*(max-min)+min; [0.0,1.0)*4=[0,4)+3=[3,7) [3,7)
- [min,max] (int)(Math.random()*(max-min+1)+min);
public class Math02{
public static void main(String[] args){
System.out.println((int)(Math.random()));
//[3,7) //[3,7]
int i= (int)(Math.random()*(7-3+1)+3);
System.out.println(i);
System.out.println(Math.round(1.49));
System.out.println(Math.abs(-1.49));
System.out.println(Math.sqrt(2));
/*
随机产生一个a~z之间的小写字母,判断是否是元音 a e i o u
*/
char ch = (char)(Math.random()*26+'a');
switch(ch){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println(ch+"是元音字母");
break;
default:
System.out.println(ch+"不是元音字母");
break;
}
}
}