Java 表达式开始错误非法:两行错误?
我是一名初学者,正在做一个学校的编码项目。我写的代码杂乱无章,风格也不太好,但这就是我理解如何编写它的方式。我只在三行上有18个错误,我不知道哪里出了错。以下是我的错误:Java 表达式开始错误非法:两行错误?,java,arrays,compiler-errors,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
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
Band.java:42:表达式的非法开始
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
java:42:表达式的非法开始
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
java:42:“;”应为
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
Band.java:42:'应为.class'
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
java:42:“;”应为
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
Band.java:42:预期值
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
java:42:表达式的非法开始
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
java:42:“;”应为
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
java:42:不是一个语句
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
java:42:“;”应为
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
java:42:“;”应为
专用静态无效计算(整数箭头、双[][]位置、整数[]行数、双总计){
^
java:85:'else'没有'if'
}否则{
^
java:115:表达式的非法开始
专用静态双总重量(双[]单行){
^
java:115:表达式的非法开始
专用静态双总重量(双[]单行){
^
java:115:“;”应为
专用静态双总重量(双[]单行){
^
Band.java:115:“应为.class”
专用静态双总重量(双[]单行){
^
java:115:“;”应为
专用静态双总重量(双[]单行){
^
java:123:解析时到达文件末尾
}
^
18个错误
这是我的代码:
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;
}
}
//=============================================================================
import java.util.Scanner;
//=============================================================================
公营乐队{
//-----------------------------------------------------------------------------
专用静态扫描仪键盘=新扫描仪(System.in);
//-----------------------------------------------------------------------------
公共静态void main(字符串[]args){
整数;
双[]个职位;
双倍总数;
整数位置;
System.out.println(“欢迎来到小时乐队”);
System.out.println(“请输入行数:”);
numberRows=keyboard.nextInt();
而(numberRows<0&&numberRows>10){
System.out.println(“超出范围,请重试:”;
numberRows=keyboard.nextInt();
}
位置=新整数[numberRows][];
对于(int索引=0;索引8){
System.out.println(“超出范围,请重试:”;
}
职位=新的双[numberRows][numberPositions];
}
对于(int i=0;i 如果(positionNumber>=1&&positionNumber=45.0&&weight您忘记了一个接近参数。您可能会发现更容易
if (weight >= 45.0 && weight <= 200) { // this line's got your if...
weight = positions[rowNumber][positionNumber];
} else { // this is fine
System.out.println("Out of range, try again");
weight = keyboard.nextDouble();
} else { // this is causing the problem
System.out.println("Out of range, try again :");
positionNumber = keyboard.nextInt();
} // this line is where the compiler is returning the error
// it's the end of the problematic else block