//首先我们可以先把名字搞成一个数组,或者List都是可以的。
10年的柳南网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整柳南建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联建站从事“柳南网站设计”,“柳南网站推广”以来,每个客户项目都认真落实执行。
String[] arr = {"张三","李四","王五","xxx"....};
String random = arr[new Random().nextInt(arr.size())];
System.out.println("随机名字为:"+random);
import java.io.BufferedInputStream;import java.util.Scanner; public class test1 { public static void main(String[] args) { Scanner cin = new Scanner(new BufferedInputStream(System.in)); int n = cin.nextInt(); // 输入n个数 int[] a = new int[n]; for (int i = 0; i n; ++i) { a[i] = cin.nextInt(); } cin.close(); for (int i = a.length - 1; i = 0; --i) { // 逆序输出 System.out.print(a[i] + " "); } }}
import java.util.Random;
public class RandomD {
public static void main(String[] args) {
System.out.println("随机点名开始!我将要在5个同学中点名!");
String[] student={"张三","李四","王五","麻子","小猪"};
Random rand=new Random();
System.out.println("点名开始:");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(student[Math.abs(rand.nextInt()%5)]);
}
}
public class test {
public static void main(String[] args) {
//定义人名数组
String [] name = {"张三","李四","王五","八神庵","不知火舞","大蛇","景天","唐雪见","李逍遥","赵灵儿"};
//随机生成数组下标、
int num = (int)(Math.random() * 1000);
//对生成的随机数进行判断,如果小于数组下标,就跳出循环
while (numname.length-1) {
if (num=name.length-1) {
break;
}
num = (int)(Math.random() * 1000);
}
//将数组下标设置成随机数,就可以实现人名的随机抽取
System.out.println(“被抽到的同学是:”+name[num]);
}
}