gpt4 book ai didi

java - ' )' expected error .... Can' 弄清楚这个

转载 作者:行者123 更新时间:2023-12-01 06:39:19 25 4
gpt4 key购买 nike

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

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

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 的专家。非常感谢任何帮助。

最佳答案

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

关于java - ' )' expected error .... Can' 弄清楚这个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18246544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com