class test3
{
public static void main(String args[])
{
int count=0;
for (int i=0;i<=100;i++)
count=count++;
System.out.println(count);
}
}
晕死,count++值怎么可能=0
追答呵呵。这是前加和后加的问题了
count++后加,先取值再加1
比如
int count=0;
int a=count++;
这是a=0;
++count 前加,先加后取值
int count=0;
int a=++count;
这时a=1
其实前加,后加,我是这样记的。加号在前,先加后取值,加号在后,先取值再加
如果细 了讲
第一例子后
a=0
count=1
第二个例子后
a=1
count=1
你没看清题、count=count++在for循环里面!
追答呵呵。我看清楚了。我说的这个例子只是为了举例说明。
道理是一样的。
你的相当 于count=(count++);
你只要明白count++等于多少就明白了
要不你这样更直观
你在for外面定义一个
int a=0;
然后在for结束后输出
a 和count。
补充完整
int count=0;
int a=0;
for (int i=0;i<=100;i++)
a=count++;
System.out.println(a);
System.out.println(count);
你去看看结果吧,估计你绕晕了
你会发现一个是100,一个101
而count=count++;
第一次count++的值为0,所以count=0
第二次循环第一次结果。。
希望楼主慢慢体会下