gpt4 book ai didi

java - 表达式开头错误: errors with two lines?

转载 作者:行者123 更新时间:2023-12-02 11:09:12 25 4
gpt4 key购买 nike

我是一个初学者,正在从事学校编码项目。我编写的代码杂乱无章,风格不好,但这就是我理解如何编写的代码。我只在三行上留下18个错误,无法弄清楚我要去哪里。这是我的错误:

Band.java:42: illegal start of expression
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:42: illegal start of expression
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:42: ';' expected
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:42: '.class' expected
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:42: ';' expected
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:42: <identifier> expected
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:42: illegal start of expression
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:42: ';' expected
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:42: not a statement
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:42: ';' expected
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:42: ';' expected
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
^

Band.java:85: 'else' without 'if'
} else {
^

Band.java:115: illegal start of expression
private static double totalWeight(double []singleRow){
^

Band.java:115: illegal start of expression
private static double totalWeight(double []singleRow){
^

Band.java:115: ';' expected
private static double totalWeight(double []singleRow){
^

Band.java:115: '.class' expected
private static double totalWeight(double []singleRow){
^

Band.java:115: ';' expected
private static double totalWeight(double []singleRow){
^

Band.java:123: reached end of file while parsing
}
^
18 errors

这是我的代码:
    import java.util.Scanner;
//=============================================================================
public class Band {
//-----------------------------------------------------------------------------
private static Scanner keyboard = new Scanner(System.in);
//-----------------------------------------------------------------------------
public static void main(String[] args) {

int numberRows;
double [][] positions;
double total;
int numberPositions;

System.out.println("Welcome to Band of the Hour");
System.out.println("Please enter number of rows: ");
numberRows = keyboard.nextInt();
while (numberRows < 0 && numberRows > 10) {
System.out.println("Out of range, try again: ");
numberRows = keyboard.nextInt();
}

positions = new int[numberRows][];

for (int index=0; index<numberRows; index++) {
System.out.println("Please enter number of positions in row " + (char)(rowNumber + (int)'A') + " : ");
numberPositions = keyboard.nextInt();
while (numberPositions < 1 && numberPositions > 8) {
System.out.println("Out of range, try again: ");
}
positions = new double[numberRows][numberPositions];
}
for(int i=0; i < positions.length; i++) {
for(int j=0; j< positions[i].length; j++) {
positions[i][j] = 0.0;
}

calculate(numberRows, positions, rowNumber, total);

}

//-----------------------------------------------------------------------------
private static void calculate (int numberRows, double[][] positions, int[] rowNumber, double total) {
char operation;
int rowLetter;
int positionNumber;
double weight;

do {
System.out.println("(A)dd, (R)emove, (P)rint, e(X)it : ");
operation = keyboard.next().toUpper().charAt(0);
switch (operation) {
case 'A':
System.out.println("Please enter row letter :");
rowLetter = (int)keyboard.next().toUpper().charAt(0)-'A';
if (rowLetter < numberRows) {
System.out.println("Please enter position number (1 to" + positions[rowNumber].length + ") :");
positionNumber = keyboard.nextInt();
if (positionNumber >= 1 && positionNumber <= positions[rowNumber].length) {
System.out.println("Please enter weight (45.0 to 200.0)");
weight = keyboard.nextDouble();
if (weight >= 45.0 && weight <= 200.0) {
if (total <= 100 * positions[rowNumber].length) {
if (0 = positions[rowNumber][positionNumber]) {
weight = positions[rowNumber][positionNumber];
System.out.println("****** Musician added.");
} else {
System.out.println("There is already a musician there. :");
}
} else {
System.out.println("That would exceed the row weight limit :");
}
} else {
System.out.println("ERROR: Out of range, try again :");
}
} else {
System.out.println("Out of range, try again");
weight = keyboard.nextDouble();
if (weight >= 45.0 && weight <= 200) {
weight = positions[rowNumber][positionNumber];
} else {
System.out.println("Out of range, try again");
weight = keyboard.nextDouble();} else {
System.out.println("Out of range, try again :");
positionNumber = keyboard.nextInt();
}
}
break;
case 'R':
System.out.println("Please enter row letter :");
rowLetter = (int)keyboard.next().toUpper().charAt(0)-'A';
if (rowLetter < numberRows) {
System.out.println("Please enter position number (1 to" + positions[rowNumber].length + ") :");
positionNumber = keyboard.nextInt();
if (positions[rowNumber][positionNumber] =! 0) {
positions[rowNumber][positionNumber] = 0;
System.out.println("****** Musician removed.");
} else {
System.out.println("That position is vacant :");
}
} else {
System.out.println("Out of range, try again :");
}
break;
case 'P':
System.out.printf("%5d ", positions[rowNumber][positionNumber]);
break;
default: System.out.println("Out of range, try again");
}
} while (operation != 'X');
}
//-----------------------------------------------------------------------------
private static double totalWeight(double []singleRow){
int index;
double total = 0.0;
for(index = 0; index < singleRow.length; index++){
total = total + singleRow[index];
}
return total;
}
}
//=============================================================================

最佳答案

你忘了亲爱的。您可能会发现,使用IDE可以更轻松地使这些事情变得容易。

关于java - 表达式开头错误: errors with two lines?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33492318/

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