java:如何随机显示输出

时间:2012-04-24 11:49:06

标签: java java-me

我有两条消息“作业1”和“作业2”。我想将这些消息放入循环中,每次执行时都会随机显示输出:如

Job1
job2
job2
job1
and so on.. 

1 个答案:

答案 0 :(得分:2)

使用Random class

将它们放入列表中,然后说:

for(i = 0; i < howeverManyTimesYouWantToLoop; i++) {
  System.out.println(jobList.get(new Random().nextInt(jobList.size()));
}