错误:不是声明Else(

时间:2013-09-18 20:04:17

标签: java if-statement compiler-errors

我是一名大学计算机科学专业的学生,​​我似乎无法找出这段代码的错误。如果我能得到一些帮助,将不胜感激。尝试编译程序时有一个错误,它是

  

Quiz4.java:27:错误:不是声明Else(。

代码:

import java.util.Scanner;

public class Quiz4
{
    public static void main(String [] args)
    {
    System.out.println(
                    "\nAuthor: Allen Watson \n" +
                    "Class: \tCSCI 1250-001 \n" +
                    "Date: \t09/18/2013 \n" +
                    "Lab: \tQuiz4 \n");
    Scanner Keyboard = new Scanner(System.in);

    String strBornState;
    String strCurrentState;

    System.out.print("\nWhat state were you born in:");
    strBornState = Keyboard.nextLine();

    System.out.print("\nWhat state do you currently live in:");
    strCurrentState = Keyboard.nextLine();

    if(strBornState.equalsIgnoreCase(strCurrentState))

        System.out.print("\nYou live in the same state you were born in:" + strBornState);

    else(
        System.out.print("\nYou DO NOT live in the same state you were born in:" +  strCurrentState));






System.out.print("\n You were born in:" + strBornState.toUpperCase());

    System.out.print("\nYou live in:" + strCurrentState.toLowerCase());



    }
}

3 个答案:

答案 0 :(得分:6)

使用大括号{}括起一个块,而不是括号()。变化:

else(
    System.out.print("\nYou DO NOT live in the same state you were born in:" +
        strCurrentState));

else {
    System.out.print("\nYou DO NOT live in the same state you were born in:" +
        strCurrentState); 
}

答案 1 :(得分:0)

删除(在其他

之后)
else{
        System.out.print("\nYou DO NOT live in the same state you were born in:" +  strCurrentState));

}

答案 2 :(得分:0)

else添加了额外的不必要的无关括号。
因此,将else(更改为else 阅读syntax of if-else