import java.util.Scanner;
public ststic void main string(args[]){
System.out.println("I want to keep randomize between following texts:")
//abc_123_def
//jaofn_3vfdsa
//nabdoew-8943
}
public static void main(String[] args) {
//task: show one of these texts randomly every time the user answers "yes"
String[] text = {"abc_123_def", "jaofn_3vfdsa", "nabdoew-8943"};
boolean bored = false;
Scanner s = new Scanner(System.in);
while (!bored) {
System.out.println("Would you like to keep randomizing?");
if (s.nextLine().equals("yes")) {
int rand_n = (int) Math.round(Math.random() * 2);
System.out.println("Random text: " + text[rand_n]);
}
else {bored = true;}
}
}
2条答案
按热度按时间4dbbbstv1#
我想这就是你想要的。。。
dsekswqp2#
你可以储存不同的
String
在一个List
,然后洗牌您可以自定义打印,使用
join
例如