0

現時点では、配列からランダムな文字列を取得できないという 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 に変更すると、コア クラスに沿ってあらゆる種類のエラーがスローされます。何が間違っているのかわかりません。誰でも助けることができますか?

4

2 に答える 2

0

コアを配列として使用していますが、文字列として定義されています

private static String core;

だからあなたはできない

tpiCore.core[...]

あなたは次のようなことをするべきです

tpiCore.insults[...]
于 2013-05-10T09:01:16.077 に答える