3 - 6 编程练习
来源:3-6 编程练习
目訫
2018-11-02 17:31:54
public class IfDemo {
public static void main(String[] args) {
// 定义整型变量x和y,值分别为-2和0
int x = -2,y = 0;
//如果x大于0,则y的值为2*x+1
//否则y的值为x+5
if(x > 0) {
y = 2 * x +1;
} else {
y = x + 5;
}
//分别输出x和y的值
System.out.println("x=" + x);
System.out.println("y=" + y);
}
}1回答
正确哦~继续加油!