Java编译错误:无法找到符号

时间:2014-02-24 08:41:26

标签: java symbols

我的任务是:

创建满足以下要求的Java程序:

  • 创建名为MaxScore.java的单个Java源文件
  • 创建一个名为MaxScore的单个类
  • MaxScore类有两种方法:
    • main
    • maxScore

maxScore方法需要七个整数参数 调用时,maxScore方法返回七个输入参数中最大的一个

主要方法执行七次以下步骤:

  • 写入STDOUT:输入分数:
  • 从STDIN读取整数值并将其存储在新变量
  • main方法使用从中获得的七个整数调用maxScore STDIN
  • 主要方法在STDOUT中写入以下最高分 格式:最高分为:

我的主要问题是没有定义符号。我已经尝试了很多次没有运气。我确信这是一个相当容易解决的问题,但我真的很感激一些帮助。 这是我的代码:

    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

2 个答案:

答案 0 :(得分:2)

您应该正确声明变量int z,a,b,c,d,e,f,g;并在中读取所有值后仅计算的最高分数。

答案 1 :(得分:0)

请声明您的变量 int a,b,c,d,e,f,g; 不是你已经做过的方式。