作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用下面的代码,即使我输入的数字大于 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/
我是一名优秀的程序员,十分优秀!