day03-判断流程-if语句-三种格式

This commit is contained in:
2026-04-25 10:36:12 +08:00
parent 74ee610223
commit 88f11c28c2

View File

@@ -27,4 +27,19 @@ public class Demo03 {
当x<1 y = 2x 1;
根据给定的x的值计算出y的值并输出。
*/
public static void main(String[] args) {
int x = 2;
int y;
if (x >= 3) {
y = 2*x + 1;
} else if (x >= -1 && x < 3) {
y = 2 * x;
} else {
y = 2 * x - 1;
}
System.out.println("x的值是"+x+"y的值是"+y);
System.out.println("程序结束");
}
}