import java.util.Scanner;
public class Test5{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
if(a>0&&a<=18){
System.out.println("少年");
}
else if(a>=19&&a<=28){
System.out.println("青年");
}
else if(a>=29&&a<=55){
System.out.println("中年");
}
else if(a>=56){
System.out.println("老年");
}else{
System.out.println("error!");
} sc.close();
}
}
根据年龄, 来打印出当前年龄的人是少年(低于18), 青年(19-28), 中年(29-55), 老年(56以上)
本文介绍了一个简单的Java程序,用于根据输入的年龄判断并输出所属年龄段:少年、青年、中年或老年。通过Scanner类读取用户输入,使用if-else语句进行条件判断。

被折叠的 条评论
为什么被折叠?



