我的分配是這樣的:Java的編譯錯誤:符號不能被發現
創建滿足以下要求的Java程序:
- 創建一個名爲MaxScore.java
- 創建一個Java源文件名爲MaxScore一個類
- 的MaxScore類有兩個方法:
- 主要
- maxScore
的maxScore方法需要七個整數參數 呼叫時,maxScore方法返回最大的七個輸入參數
主要方法執行以下步驟七次:
- 寫入STDOUT:輸入得分:
- 從STDIN讀取一個整數值並將其存儲在一個新的v良莠不齊
- 主要方法調用maxScore從 STDIN
- 主要方法寫入到標準輸出的最高分以下 格式獲得的7個整數:最高得分爲:
我的主要問題是,該符號未被定義。我試過這一堆,沒有運氣。我相信這是一個相當容易解決問題,但我真的很感謝一些幫助。 這裏是我的代碼:
import java.util.Scanner;
public class MaxScore1{
public static void main(String[] args){
//establishes the main method first
int z = a,b,c,d,e,f,g;
z = maxScore(a,b,c,d,e,f,g);
Scanner foo = new Scanner(System.in);
//repeating the code 7 times in order to get 7 integers that are the scores
System.out.print("Enter a score: ");
a = foo.nextInt();
System.out.print("Enter a score: ");
b = foo.nextInt();
System.out.print("Enter a score: ");
c = foo.nextInt();
System.out.print("Enter a score: ");
d = foo.nextInt();
System.out.print("Enter a score: ");
e = foo.nextInt();
System.out.print("Enter a score: ");
f = foo.nextInt();
System.out.print("Enter a score: ");
g = foo.nextInt();
System.out.println("Maximum value returned by maxScore is " + z + ".");
}
public static int maxScore(int a,int b,int c,int d,int e,int f,int g){
//calling all the integers obtained earlier
int x;
//establishing a base for the currentscore
x = 0;
//establishing the variable
if (a > x){
//a set of if statements to return the maximum value
x = a;
}
if (b > x){
x = b;
}
if (c > x){
x = c;
}
if (d > x){
x = d;
}
if (e > x){
x = e;
}
if (f > x){
x = f;
}
if (g > x){
x = g;
}
return x; //returning the maximum value obtained.
}
}
我的錯誤是:
MaxScore1.java:6: error: cannot find symbol
int z = a,b,c,d,e,f,g;
^
symbol: variable a
location: class MaxScore1
MaxScore1.java:8: error: cannot find symbol
z = maxScore(a,b,c,d,e,f,g);
^
symbol: variable a
location: class MaxScore1
MaxScore1.java:13: error: cannot find symbol
a = foo.nextInt();
^
symbol: variable a
location: class MaxScore1
3 errors
忽略你沒有聲明這些變量,試圖在*之前計算一些*你已經接受了輸入可能不會奏效。 –
[你試過](http://whathaveyoutried.com)使用谷歌搜索錯誤信息?這應該永遠是你的第一步。 – starsplusplus