JAVA编程入门教程(21)
2015-11-22编辑:guomu
取随机数
方法1;
import java.util.Random;
public class Test{
public static void main(String[] args){
Random a=new Random();
int number=a.nextInt(100);
System.out.println("随机数为"+number);
}
}
方法2:
public class Test{
public static void main(String[] args){
int number=(int)(Math.random()*10);
System.out.println(number);
}
}