public class E {
public static void main (String []args) {
int x = 1,y = 6;
while (y-->0) {
x--;
}
System.out.print("x="+x+",y="+y);
}
}
我将这个程序运行出来是x=-5,y=-1,这个是为什么?可以讲详细点吗?谢谢!
public class E {
public static void main (String []args) {
int x = 1,y = 6;
while (y-->0) {
x--;
}
System.out.print("x="+x+",y="+y);
}
}
我将这个程序运行出来是x=-5,y=-1,这个是为什么?可以讲详细点吗?谢谢!
while执行7次,前6次条件为TRUE,导致x被减了6次,所以为-5,最后一次循环时,y为0,条件不满足,但y--会导致y被再次减1,就成了-1了