我想写出100以内奇数的和,为什么加不加(num % 2 != 0)判断条件,运算结果都是一样的?
int sum = 0;
int num = 1;
do {
sum = sum + num;
num = num + 2;
} while ( num <=100 );
System.out.println(" 100以内的奇数之和为:" + sum );
与
int sum = 0;
int num = 1;
do {
sum = sum + num;
num = num + 2;
} while ( num <=100 && num % 2 != 0 );
System.out.println(" 100以内的奇数之和为:" + sum );
为什么结果都是一样的