我不知道如何修复此错误:解析时到达文件末尾

时间:2016-10-04 04:09:55

标签: java

运行此代码时,我一直得到同样的错误,我以为我用括号修正了错误,但我错了。

gcm <name>

错误是

public class INCOME {
public static void main(String[] args) 
{
int income = 4001;
if (income > 3000) {
JOptionPane.showMessageDialog(null, "Income is greater than 3000");
}
else if (income > 4000) {
JOptionPane.showMessageDialog(null, "Income is greater than 4000");
}
else if (income > 5000) {
JOptionPane.showMessageDialog(null, "Income is greater than 5000");

}
}

2 个答案:

答案 0 :(得分:0)

你缺少一个大括号,添加一个后它应该运行正常。

import javax.swing.*;

public class INCOME {
public static void main(String[] args) {
    int income = 4001;
    if (income > 3000) {
        JOptionPane.showMessageDialog(null, "Income is greater than 3000");
    } else if (income > 4000) {
        JOptionPane.showMessageDialog(null, "Income is greater than 4000");
    } else if (income > 5000) {
        JOptionPane.showMessageDialog(null, "Income is greater than 5000");

    }
}
} //This guy here :)

答案 1 :(得分:0)

最后你有两个结束括号。倒数第二个关闭else if。最后一个关闭了main,因此没有任何关闭类INCOME。最后再添加一个大括号}。另外,交换测试。由于50004000 两者大于3000。所以第一次测试将是真的。

public class INCOME {
    public static void main(String[] args) {
        int income = 4001;
        if (income > 5000) { // <-- first.
            JOptionPane.showMessageDialog(null, "Income is greater than 5000");
        } else if (income > 4000) {
            JOptionPane.showMessageDialog(null, "Income is greater than 4000");
        } else if (income > 3000) {
            JOptionPane.showMessageDialog(null, "Income is greater than 3000");
        }
    } // <-- this is the last brace in your code.
} // <-- you don't have this one.