求50以內(nèi)奇數(shù)的和 這個代碼為什么輸出是空的
public class XiaoYang {
? ? public static void main(String[] args) {
? ? int a=0;
? ? int b=0;
? ? //求50以內(nèi)基數(shù)的合。
? ? for(a=0;a<=50;a++){
? ? while(a%2!=0){
? ? b+=a;
? ? }
? ? }
? ? System.out.println(b);
? ? ?}
? }
? ??
2016-07-30
public class Test
{
?public static void main(String[] args)?
{
? ? int a=0;
? ? int b=0;
? ? //求50以內(nèi)奇數(shù)的合。
? ? for(;a<=50;a++)
{
? ? while(a%2!=0)
{
? ? b+=a;
break;
? ? ? ? }
? ? ? ? }
? ? System.out.println(b);
? ? ?}
}
2016-07-07
while(a%2!=0){? b+=a;}???, 這個的運行過程是? 先判斷? a%2!=0,a是奇數(shù),成立的話就執(zhí)行b+=a, 然后重復(fù)執(zhí)行判斷,因為a 沒有變化所以判斷一直成立,也一直執(zhí)行b+=a, 也自然走不到print的那步, while 改成 if 就可以了
2016-03-31
好像a是奇數(shù)時 卡在while()循環(huán)里了,改成if
2016-03-31
檢查一下所有的;是否為 英文輸出