-1

私はすべてのプログラミングの割り当てを最初に日食で行い、その後パテに入れて教師に提出します。Eclipseでは、メソッドの1つにこの奇妙なエラーがあります。

「トークンの構文エラー、誤って配置された構成」と表示されます。

public static int factorial(int iVal, boolean DEBUG)
{
 int result;
    // Defensive programming
 if(iVal <= 0)
 {
  System.out.println("Error: iVal cannot be a negative number!");
  System.exit(0);
 }
    // Calculate result
 int factor = iVal;
 int counter = iVal - 1;
 for(int i = counter; i > 1; i--)
 {
  if(DEBUG = true)
  {
   System.out.println("DEBUG");
    System.out.println("   Finding the factorial of " + factor);
   System.out.println("   Currently working on " + i);
   System.out.println("   With an intermediate result of" + iVal);
  }
  iVal *= i;
 }
       result = iVal;
    // Return result
       return result;
} // End of factorial method

次の行にエラーがあります。

System.out.println("   Currently working on " + i);

何か案は?

4

2 に答える 2

4
if(DEBUG = true)

比較は==、割り当ては=
また、ブール値をテストするだけの場合は、比較を行う必要はまったくなく、単に使用するだけです

if(DEBUG)
于 2010-10-31T19:59:11.140 に答える
1

if ステートメントに割り当てがあります。

if(DEBUG = true){

DEBUGこれは、タイプが であるため有効です (そしてコンパイルされます)booleanが、常にtrueです。

于 2010-10-31T20:03:52.950 に答える