day03-判断流程-if语句-三种格式
This commit is contained in:
@@ -27,4 +27,19 @@ public class Demo03 {
|
|||||||
当x<‐1 y = 2x – 1;
|
当x<‐1 y = 2x – 1;
|
||||||
根据给定的x的值,计算出y的值并输出。
|
根据给定的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("程序结束");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user