2015-12-23 17 views
0

我得到一個編譯錯誤與簡單的輸出語句:CAN找不到符號

System.out.println(j); 

但是,如果沒有它,它編譯罰款。

其次,每當for(condition)爲真時,它將迭代,但它會如何4/2(不會J迭代到3)?

希望是有道理的。

public class FindFac { 
    public static void main(String args[]) { 

    for(int i = 2; i <= 50; i++) { 
     System.out.print("Factors of " + i + ": "); 
     for(int j = 2; j < i; j++) 
      ***System.out.println(j);*** 
     if((i%j) == 0) System.out.print(j + " "); 
     System.out.println(); 
    } 
} 
} 

回答

0

它是一種非常愚蠢的錯誤,你錯過了循環的開啓和關閉括號:

public static void main(String args[]) { 

     for (int i = 2; i <= 50; i++) { 
      System.out.print("Factors of " + i + ": "); 
      for (int j = 2; j < i; j++) { 
       System.out.println(j); 
       if ((i % j) == 0) System.out.print(j + " "); 
      } 
      System.out.println(); 
     } 
    } 
}