Java零基础入门:运算符练习

时间:2025-04-04 09:22:25
public class Test04 { public static void main(String[] args){ boolean raining = false; if(raining){ System.out.println("外面下雨了,出门记得带一把伞哦!"); }else{ System.out.println("天气不错哦!"); } boolean eatFull = true; if(eatFull){ System.out.println("吃的好饱啊!"); }else{ System.out.println("还没有吃饱,再来份米饭!"); } boolean sex = true; if(sex){ System.out.println("男"); System.out.println("Hello world!"); } else{ System.out.println("女"); } java.util.Scanner scan = new java.util.Scanner(System.in); System.out.print("请输入数字;"); int i = scan.nextInt(); if(i==1){ System.out.println("性别:男"); }else if(i==0){ System.out.println("性别:女"); }else{ System.out.println("对不起,你输入不合法!"); } System.out.print("输入考试成绩:"); int score = scan.nextInt(); String grade = "大笨蛋"; if(score < 0 || score > 100){ grade = "对不起,您输入的成绩不合法!"; }else if(score >= 90){ grade = "优秀"; }else if(score >= 80){ grade = "良好"; }else if(score >= 70){ grade = "中等"; }else if(score >= 60){ grade = "及格"; } System.out.println("成绩等级:" + grade); } }