我收到编译错误:')' 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
我已经用谷歌搜索了这个问题,但无法弄清楚,所以我正在咨询 Stack Overflow 的专家。非常感谢任何帮助。