问题:
Given the following code:
public class Test {
void printValue(int m){
do {
System.out.println("The value is"+m);
}
while( --m > 10 )
}
public static void main(String arg[]) {
int i=10;
Test t= new Test();
t.printValue(i);
}
}
Which will be output?()
A . The value is 8
B . The value is 9
C . The value is 10
D . The value is 11
Given the following code:
public class Test {
void printValue(int m){
do {
System.out.println("The value is"+m);
}
while( --m > 10 )
}
public static void main(String arg[]) {
int i=10;
Test t= new Test();
t.printValue(i);
}
}
Which will be output?()
● 参考解析
此题考察的是do… while循环和 -- 操作符的知识,do…while最少被执行一次,在执行完do中的内容后判断while中的条件是否为true,如果为true的话就再执行do中的内容,然后再进行判断,以此类推直到while的判断为false时退出循环执行循环后面的内容,而—操作符的规则是在变量右边的-- 将先进行运算,然后才是使变量的值减一,而在变量左边的是先将变量的值减一再运算。
相关内容
相关标签