我有以下應該運行的程序,但它不是。教授給了我們合作。它旨在計算階乘。它甚至不會讓我編譯。錯誤我正在狀態遞歸程序中的錯誤
Multiple markers at this line - Syntax error on token "Invalid Character", invalid Expression - Syntax error on tokens, delete these tokens
這是在參考了以下行:
System.out.print (「%d! = %d\n」, counter, factorial (counter));
我該如何解決這個問題?我之前編寫過很多程序,但之前我從來沒有在引號內看到過模運算符。我有點困惑!整個計劃在下面發佈!謝謝!
public class FactorialTest
{
// calculate the factorial of 0 – 15
public static void main (String args[])
{
FactorialCalculation factorialCalculation = new FactorialCalculation();
factorialCalculation.displayFactorials();
} // end of main
} // end of the class FactorialTest
public class FactorialCalculation
{
//recursive Factorial method
public long factorial(long number)
{
if (number <= 1)
return 1;
else
return number * factorial (number - 1);
}
//Now output the factorials of 0 through 15
public void displayFactorials()
{
// Calculate the factorial of o through 15
for (int counter = 0; counter <= 10; counter++)
System.out.print (「%d! = %d\n」, counter, factorial (counter));
} // end of the method displayFactorials
} // end of class FactorialCalculation
不要使用彎引號。 –