需求分析
Java数组实现的简单点名器
用数组将名单存储,然后调用Random函数取随机数实现随机点名。
代码实现
import java.util.Random;
public class DianMingDemo {
public static void main(String[] args) {
//点名器 数组存储名字
String[] name = {"小李","小2","小3","小4","小5","小6","小7","小8","小9","小10","小11"};
Random random = new Random(); //获取随机数
int i = random.nextInt(11)+1;
System.out.println(name[i]);
}
}
小结Time
很Easy啦!!