得到错误';'期待的java

时间:2014-07-23 03:29:35

标签: java arrays

我不知道代码中的错误是什么。我只是从教程中复制它并且它有一个错误,但在教程中它完全在这里运行代码。

class arraye {
public static void main(String[] args) {

int[] testResult;
testResult = new int[30];

testResult[0] = 87;

String[] DaysOfTheWeek = { "Monday", "Tuesday", "Wednesday", "Thursday, "Friday" };

System.out.print("Test Result: " + testResult[0]);
System.out.print("Day: " + DaysOfTheWeek[2]);


}
}

3 个答案:

答案 0 :(得分:3)

你周四在这里错过了一个近距离的报价,

String[] DaysOfTheWeek = { "Monday", "Tuesday", "Wednesday", "Thursday, "Friday" };

应该是

String[] DaysOfTheWeek = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };

答案 1 :(得分:2)

这可以解决您的问题:

String[] DaysOfTheWeek = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };

问题是Quoted字符串未正确终止。因此,它会将“Thursday ,”(星期四用逗号和空格)视为一个值,Friday不会作为字符串而是作为一些未定义的变量。因为它在语法上是不正确的,所以你会得到异常。

答案 2 :(得分:2)

请查看您的DaysOfTheWeek数组。你在周四结束时错过了双重报价,如

String [] DaysofTheWeek = {“”,“Wednesday”,“Thursday”,Friday“};

校正:

String[] DaysOfTheWeek = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};