java 控制流程
Java 流程控制 三大流程控制语句:顺序、选择、循环 选择结构 if 结构 判断条件是布尔类型,且是一个范围 Scanner scanner = new Scanner(System.in); int score = scanner.nextInt(); if (score >= 90) { System.out.println("优"); } if (score >= 80 && score < 90) { System.out.println("良"); } if (score >= 60 && score < 80) { System.out.println("中"); } if (score < 60) { System.out.println("不及格"); } 多重 if if (score >= 90) { System.out.println("优"); } else if (score >= 80) { System.out.println("良"); } else if (score >= 60) { System.out.println("中"); } else { System.out.println("不及格"); } 嵌套 if 将整个 if 块嵌套到另一个 if 块中 public static void main(String[] args) { // 定义两个整型变量并初始化 int x, y; Scanner scanner = new Scanner(System.in); x = scanner.nextInt(); y = scanner.nextInt(); // 判断 x 和 y 是否相等 if (x != y) { if (x > y) { System.out.println("x 大于 y!"); } else { System.out.println("x 小于 y!"); } } else { System.out.println("x 和 y 相等!"); } } switch结构 判断条件是一个常量 ...