我正在为明天的介绍性学习sci测试,需要能够确定不同操作的价值。用我的计算,t应该等于8。但是当编译它时,它会返回11。如果2不大于3,它为什么要运行第二。我知道这可能只是一个误解问题,但它确实会有帮助。提前谢谢。
public class Prac {
public static void main(String []args){
int i=4, j=3, k=10;
float r=3, s=2, t=5;
boolean done = false;
if (s*2 >= j && t >= s) {
if (s>j)
s++;
t = t * s;
} else
t += s;
t++;
System.out.println(t);
}
}发布于 2018-11-15 05:56:56
外部条件为真,内部条件为假。
因此,执行的语句是:
t = t * s; // 5 * 2 == 10和
t++; // 11通过适当的缩进和大括号,代码将更加清晰:
if (s*2 >= j && t >= s) { // 2 * 2 >= 3 && 5 >= 2 - true
if (s>j) { // 2 > 3 - false
s++; // not executed
}
t = t * s; // executed
} else {
t += s; // not executed
}
t++; // executedhttps://stackoverflow.com/questions/53313242
复制相似问题