AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
>[success] # if /else if /if -- 判断 * `条件` 判断条件表达式是否成立 ~~~ if (条件) { // 条件满足时执行 语句块1; }else if(条件){ // 条件满足时执行 语句块2; }else{ // 条件满足时执行 语句块3; } ~~~ >[danger] ##### 判断考试成绩 ~~~ import java.util.Scanner; public class IfTest { public static void main(String[] args) { System.out.println("输入考试成绩"); // 获取成绩 Scanner sc = new Scanner(System.in); int scores = sc.nextInt(); if (scores >= 90) { System.out.println("成绩优秀" ); } else if (scores >= 60) { System.out.println("成绩及格"); } else { System.out.println("成绩不及格"); } } } ~~~ >[danger] ##### 税率计算 ~~~ import java.util.Scanner; public class IfTest { public static void main(String[] args) { System.out.println("工资"); Scanner sc = new Scanner(System.in); // 输入工资 int salary = sc.nextInt(); // 交税金额 double 类型 double salaryPrice = 0.0; if (salary <= 5000) { } else if (salary <= 8000) { salaryPrice = (salary - 5000) * 0.03; } else if (salary <= 17000) { salaryPrice = (salary - 5000) * 0.1 - 210; } else if (salary <= 30000) { salaryPrice = (salary - 5000) * 0.2 - 1410; } System.out.println(salaryPrice); } } ~~~