本程序中 n++; sum+=n;是两条分开的语句,先执行前面一条语句,然后执行后面。下面的程序运行时,才是n=5 sum=10
public class exam
{
public static void main(String[] args)
{
int n=0;
int sum=0;
do
{
sum+=n++; //2
}
while(sum<10) // 3
System.out.println("sum="+sum);
System.out.println("n="+n);
}
}
public class exam
{
public static void main(String[] args)
{
int n=0;
int sum=0;
do
{
sum+=n++; //2
}
while(sum<10) // 3
System.out.println("sum="+sum);
System.out.println("n="+n);
}
}