梓鹏
2018-04-09 22:13
package DailyHomework; import java.util.Random;//包含随机数需要的类 public class Homework10 { private static final int ramNum = 2; public static void main(String args[]){ String [] nameList= {"张三","李四","王五"}; int rdmNum=(int)(Math.random()*nameList.length); System.out.println(nameList[ramNum]); } }
public static void main(String args[]){
String [] nameList= {"张三","李四","王五"};
Random random=new Random();
int ramNum=random.nextInt(nameList.length);
System.out.println(nameList[ramNum]);
}
Java入门第一季(IDEA工具)升级版
1165641 学习 · 17587 问题
相似问题