gpt4 book ai didi

java - 错误 : not a statement Else(

转载 作者:行者123 更新时间:2023-12-03 18:38:14 26 4
gpt4 key购买 nike

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

8年前关闭。




Improve this question




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

Quiz4.java:27: error: not a statement 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());



}
}

最佳答案

使用大括号 {}括起一个 block ,而不是括号 () .改变:

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);
}

关于java - 错误 : not a statement Else(,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18881356/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com