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

标签 java arrays compiler-errors

我是一个初学者,正在从事学校编码项目。我编写的代码杂乱无章,风格不好,但这就是我理解如何编写的代码。我只在三行上留下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/

相关文章:

java - 从一个线程调用方法到另一个线程在另一个线程中执行

java - 检查一个数组中的所有值是否都存在于另一个数组中

compiler-errors - 无法使用 gfortran 打开模块文件

java - 如何使用opencv java识别黑色

javascript - 从java到typescript的代码片段

java - 如何调整 Jpanel 中 JTextField 的大小

java - checkin 函数时数组大小错误

javascript - Knockoutjs "foreach"相当于非数组对象

c - 错误 : A label can only be part of a statement

java - 为什么变量在循环内可见而在循环外看不到?