我是一名计算机科学专业的学生,我似乎无法找出此代码出了什么问题。如果我能得到一些帮助,将不胜感激。尝试编译程序时出现一个错误,它是
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());
}
}
用大括号{}
括起来,不要用括号括起来()
。更改:
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);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句