2015-09-25 54 views
-4

我試圖編寫代碼的階乘數程序,下面的代碼錯誤顯示在(INT I = N;我> 0;我 - )

public class Factorial { 
    public static void main(String[] args) { 
     Scanner in = new Scanner(System. in); 


     System.out.println("Enter the number whose factorial you want: "); 

     int n = in .nextInt(); 
     int f = 1; 
     for (int i = n; i & gt; 0; i--) //error show what's wrong in for loop { 
      f = f * i; 
     } 
     System.out.println("Factorial of " + n + " is " + f); 
    } 
} 
+5

你從什麼地方有複製粘貼代碼。所以'>'appare而不是'>'。 – Manwal

回答

4

是你的錯誤點是& gt;它不是一個操作員實際操作員是>>XML編碼 from >

使用此:

for (int i = n; i > 0; i--) 

而不是

for (int i = n; i & gt; 0; i--) 

這種情況通常發生在你複製過去的代碼的某個地方。


完整的代碼應該是:

public class Factorial { 
    public static void main(String[] args) { 
     Scanner in = new Scanner(System. in); 


     System.out.println("Enter the number whose factorial you want: ");  
     int n = in .nextInt(); 
     int f = 1; 
     for (int i = n; i > 0; i--) //error show what's wrong in for loop { 
      f = f * i; 
     } 
     System.out.println("Factorial of " + n + " is " + f); 
    } 
} 
+0

非常感謝你@Manwal你救我 – Ramasamy

+0

嗨@Sanjay希望這對你有所幫助。如果這是你需要的,你可以通過點擊表決底部的按鈕來接受答案。 – Manwal

相關問題