我试图制作一个DOS游戏或System.out.print并使用接口..但我不知道如何.. awwww ..我的意思是当角色受伤时通过使用随机方法amm说不同的句子 喜欢这里的代码
String sh1 = "";
String sh2 = "";
String sh3 = "";
Random r1 = new Random();
int ir1 = r1.nextInt(3)+1;
int ih1 = 1;
int ih2 = 2;
int ih3 = 3;
integer.ToString(ih1);
integer.ToString(ih2);
integer.ToString(ih3);
我希望我解释得足以理解对不起,如果我有任何错误,我在这里学习 并感谢您的理解
答案 0 :(得分:3)
这是您使用数组的地方:
String[] sh = {
"First sentence",
"Second sentence",
"Third sentence"
};
int ir1 = r1.nextInt(sh.length);
System.out.println(sh[ir1]);
请注意,数组索引以0
开头。