gpt4 book ai didi

java - 非常简单的 if else 语句不起作用。我做错了什么?

转载 作者:行者123 更新时间:2023-12-01 16:49:28 25 4
gpt4 key购买 nike

我是 Java 新手。我是自学,没有指导。谁能帮我写这段小代码吗?我做错了什么??

package Lessons;
import java.util.Scanner;
public class lesson1
{
public static void main (String []Args)
{
Scanner input = new Scanner (System.in);
int age;
System.out.println("How old are you?");
age = input.nextInt();
if (age >= 20);
System.out.print("You Passed!");
else
( age <= 20)
System.out.println("You Failed!");
}
}

问题出在其他方面。我正在使用 Eclipse,但我没有从它那里得到任何关于该做什么的帮助解决方案。

最佳答案

首先,你有“;”如果之后。为什么?

另外你不应该写“else (...)”,至少不应该写“else if(...)”

所以,如果我理解正确的话,正确的代码是:

package Lessons;

import java.util.Scanner;

public class lesson1 {
public static void main(String[] Args) {

Scanner input = new Scanner(System.in);

int age;

System.out.println("How old are you?");

age = input.nextInt();

if (age >= 20) {
System.out.print("You Passed!");
}
else {
System.out.println("You Failed!");
}
}

}

关于java - 非常简单的 if else 语句不起作用。我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43469558/

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