3-6 编程练习
来源:3-6 编程练习
mrfengyun
2019-01-12 16:54:37
package com.imooc.operator;
public class Test2 {
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 + "\ny = " + y);
}
}
1回答
好帮手慕阿满
2019-01-13
同学的代码完成的不错,继续加油。祝:学习愉快~
相似问题