0

为什么我不允许启动程序,它说:删除短语令牌。对不起noob Q(这个论坛的第一个Q)

public class Pirma {

public static void main(String[] args) {

    String[] wordlistOne = {"ziaurus", "grazus", "baisus", "fainas"};
    String[] wordlistTwo = {"afigienas", "negeras", "idomus", "juokingas"};
    String[] wordlistThree = {"nekoks", "neidomus", "lameris", "kietas"};

    int oneLength = wordlistOne.length;
    int twoLength = wordlistTwo.length;
    int threeLength = wordlistThree.length;

    int rand1 = (int) (Math.random() * oneLength);
    int rand2 = (int) (Math.random() * twoLength);
    int rand3 = (int) (Math.random() * threeLength);

    ***String phrase*** = wordlistOne[rand1] + " " + wordlistTwo[rand2] + " " + wordlistThree[rand3];
    System.out.println("What we need is" + " " ***phrase***);
}
}
4

3 回答 3

5

您忘记了+介于" "和之间phrase

于 2013-07-08T21:56:59.360 回答
3
***String phrase*** = wordlistOne[rand1] + " " + 
        wordlistTwo[rand2] + " " + wordlistThree[rand3];
System.out.println("What we need is" + " " ***phrase***);

由于所有这些星号,它是无效的。您需要删除它们并添加一个+

String phrase = wordlistOne[rand1] + " " + wordlistTwo[rand2] + " " + wordlistThree[rand3];
    System.out.println("What we need is" + " " + phrase);

编辑:阅读评论,似乎星号主要是为了强调。您的错误仍然是and+之间的缺失。" "phrase

于 2013-07-08T21:57:23.827 回答
1

尝试:

    String phrase = wordlistOne[rand1] + " " + wordlistTwo[rand2] + " " + wordlistThree[rand3];
    System.out.println("What we need is " + phrase);
于 2013-07-08T21:58:58.993 回答