all*_*iii 2 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());
}
}
Run Code Online (Sandbox Code Playgroud)
使用大括号{}括起一个块,而不是括号().更改:
else(
System.out.print("\nYou DO NOT live in the same state you were born in:" +
strCurrentState));
Run Code Online (Sandbox Code Playgroud)
至
else {
System.out.print("\nYou DO NOT live in the same state you were born in:" +
strCurrentState);
}
Run Code Online (Sandbox Code Playgroud)