理解if语句的格式和执行流程:
理解if...else语句的格式和执行流程:
理解if...else if语句的格式和执行流程:
public static void main(String[] args) { System.out.println("开始"); // x和y的关系满足如下: // x>=3 y = 2x + 1; //‐1<=x<3 y = 2x; // x<=‐1 y = 2x ‐ 1; // 根据给定的x的值,计算出y的值并输出。 int x = ‐1; int y = 0; if (x >= 3) { y = 2*x + 1; } else if (‐1 <= x && x < 3) { y = 2*x; } else if (x <= ‐1) { y = 2*x ‐ 1; } System.out.println("y = " + y); System.out.println("结束"); }
了解三元运算符和if语句互换:
理解switch选择语句的格式和执行流程: