```java // 判断正负数 if (x > 0) { System.out.println("x是正数"); } else if (x < 0) { System.out.println("x是负数"); } else { System.out.println("x是零"); }

// 判断成绩等级 if (score >= 90) { System.out.println("A"); } else if (score >= 80) { System.out.println("B"); } else if (score >= 70) { System.out.println("C"); } else if (score >= 60) { System.out.println("D"); } else { System.out.println("E"); }

// 判断一年的是否是闰年 if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { System.out.println(year + "是闰年"); } else { System.out.println(year + "是平年"); } ```

Java if-else if 语句示例:判断正负数、成绩等级和闰年

原文地址: https://www.cveoy.top/t/topic/pVvJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录