')'预期的错误....无法解决这个问题

时间:2013-08-15 04:54:36

标签: java

我收到了编译错误:')' expected error但正如您在下面的代码中看到的那样,没有任何不平衡的括号。它可能是什么。

这是我在学校作业的代码:

import java.util.*;
import java.io.*;

public class Assignment7b {


public static void main(String[] args)throws FileNotFoundException {

  ArrayMath A = new ArrayMath();

    Scanner console = new Scanner(System.in);
    System.out.print("Enter file name: ");
    String fileName = console.next();
    Scanner input = new Scanner(new File(fileName));
    int[][] matrixA = makeMatrix(input);
    int[][] matrixB = makeMatrix(input);
    int[][] matrixC = makeMatrix(input);
    int[][] matrixD = makeMatrix(input);
    int[][] addResult = A.addArrays(matrixA, matrixB);
    int[][] subResult = A.subArrays(matrixA, matrixB);
    int[][] multResult = A.multArrays(matrixC, matrixD);
    System.out.print("Output file name: ");
    String outputFile = console.next();
    output(outputFile, matrixA, matrixB, matrixC, matrixD, addResult, subResult, multResult);

}

public static int[][] makeMatrix(Scanner input) {
    int rows = input.nextInt();
    int col = input.nextInt();
    int[][] thisMatrix = new int[rows][col];
    for(int i = 0; i < rows; i++) {
        input.nextLine();
        for(int j = 0; j < col; j++) {
            int num = input.nextInt();
            thisMatrix[i][j]++;             
        }
   }
    return thisMatrix;
}

public static void output(String outputFile, int[][] matrixA, int[][] matrixB, int[][] matrixC, int[][] matrixD, int[][] addResult, int[][] subResult, int[][] multResult) throws FileNotFoundException {
    PrintStream out = new PrintStream(new File(outputFile));
    ArrayMath A = new ArrayMath();    
    out.print("MATRIX A: /n");
    out.print(A.2dArrayText(matrixA));
    out.print("MATRIX B: /n");
    out.print(A.2dArrayText(matrixB));
    out.print("A PLUS B: /n");
    out.print(A.2dArrayText(addResult));
    out.print("A MINUS B: \n");
    out.print(A.2dArrayText(subResult));
    out.print("MATRIX C: \n");
    out.print(A.2dArrayText(matrixC));
    out.print("MATRIX D: \n");
    out.print(A.print2dArray(matrixD));
    out.print("C TIMES D: \n");
    out.print(A.2dArrayText(multResult));

}

}

我的所有out.print()行都出错了。我到处检查过,看不到不平衡的括号,但我继续得到像

这样的错误
Assignment7b.java:47: ')' expected

我已经用Google搜索了这个问题但无法弄明白,所以我正在咨询Stack Overflow的专家。任何帮助非常感谢。

2 个答案:

答案 0 :(得分:10)

您不能拥有以数字开头的方法名称,如2dArrayText中所示。这会使编译器感到困惑。

答案 1 :(得分:1)

摄制

class X {
    void y() {
        System.out.println( A.1d());
    }
}

javac X.java
X.java:3: error: ')' expected
    System.out.println( A.1d());
                         ^

回答,不要使用数字作为标识符的第一个字符。