19.假设有如下程序:
public class Demo {
public static void main(String args[]) {
System.out.println(inc(10) + inc(8) + inc(-10)) ;
}
public static int inc(int temp) {
if (temp > 0) {
return temp * 2 ;
}
return -1 ;
}
}
最终执行结果是什么?
A. 35
B. 8
C. 28
D. 12
正确的答案是:A
inc(10) 调用inc方法 temp > 0 为true ,返回10*2 =20
inc(8) 调用inc方法 temp > 0 为true ,返回8*2 =18
inc(-10) 调用inc方法 temp > 0 为false ,返回-1
最后计算结果
20+18+(-1)=35