JAVA(新手Q)局部变量

时间:2013-07-08 21:55:57

标签: java variables local

为什么我不被允许发起程序,它说:删除短语令牌。抱歉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***);
}
}

3 个答案:

答案 0 :(得分:5)

您忘记了+" "之间的phrase

答案 1 :(得分: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);
编辑:阅读评论,似乎星号主要用于强调。您的错误仍然是+" "之间缺少的phrase

答案 2 :(得分:1)

尝试:

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