我的 Java 代码目前有一个小问题,我无法从我拥有的数组中获取随机字符串。我的一段代码在这里:
private static String core;
{
String[] insults = new String[15];
insults[0] = "So's your mum.";
insults[1] = "I hate you too.";
insults[2] = "Freak!";
insults[3] = "Your balls are like peas.";
insults[4] = "You're so ugly, your birth certificate was an apology letter from the condom factory.";
insults[5] = "Ooh, take me to the burn unit.";
insults[6] = "That insult was like your dick- Pathetic.";
insults[7] = "Your mum looks like a dog. I was brought up not to lie.";
insults[8] = "Can you look away? It's killing my face...";
insults[9] = "If you had a house for every good insult you gave me, you'd still be living on the streets!";
insults[10] = "Shut up, you'll never be the man your mother is.";
insults[11] = "Shut up, you'll never be the man your mother is.";
insults[12] = "Oh my God... Was your face squashed in a vice at birth?";
insults[13] = "I know you are, but what am I?";
insults[14] = "Oh, okay then...";
double count = 0;
};
public static void output(String output) {
String insult1 = tpiCore.core[(new Random()).nextInt(insults.length)];
}
您可能可以从这里看到我正在尝试做的事情。从上面的列表中选择一个随机的侮辱。如果我尝试运行代码,它会在 处引发错误tpiCore.core[(new Random()).nextInt(insults.length)];
,“说表达式的类型必须是数组类型,但它解析为字符串”。然后,当我将类型更改为 Array 时,它会沿着核心类抛出各种错误。我不知道我做错了什么。任何人都可以帮忙吗?