String[] prompts = {"Describe to me in a sentence why this is a cool program.",
"Describe to me in a sentence how your day was.",
"Describe to me in a sentence what programming means to you.",
"Describe to me in a sentence why food is neccessary for humans."};
System.out.println(prompts);
我想从数组中调用一个随机字符串,我应该如何报告它?
答案 0 :(得分:2)
只需要在数组长度范围内随机生成一个索引
int i = new Random().nextInt(prompts.length);
System.out.println(prompts[i]);