gpt4 book ai didi

java - If 语句 评估

转载 作者:行者123 更新时间:2023-12-01 17:19:21 30 4
gpt4 key购买 nike

使用下面的代码,即使我输入的数字大于 18,我也会得到这个结果。
运行:你今年多大? 21你还没有达到成年年龄!构建成功(总时间:3 秒)

我是java新手,正在尝试自学,有人可以帮忙吗?

import java.util.Scanner;
public class Chapter8 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner reader = new Scanner (System.in);
// TODO code application logic here

//Excercise 15
System.out.print("How old are you? ");
int x = Integer.parseInt(reader.nextLine());
if (x > 18){
System.out.println("You have not reached the age of Majority yet!");
}else {
System.out.println("You have reached the age of Majority!");
}

最佳答案

您的代码当前显示“如果年龄大于 18 岁(即 19 岁或以上),则他们尚未成年”。

我想你的意思是x < 18

关于java - If 语句 评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19863069/

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