Java编译错误:找不到符号 [英] Java compile error: symbol cannot be found

查看:84
本文介绍了Java编译错误:找不到符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是这样的:

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

Create a Java program that satisfies the following requirements:

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

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

    The maxScore method takes seven integer arguments When called, the maxScore method returns the largest of the seven input arguments

    main 方法执行以下步骤七次:

    The main method performs the following steps seven times:

    • 写入标准输出:输入分数:
    • 从 STDIN 读取一个整数值并将其存储在一个新变量中
    • main 方法使用从标准输入
    • main 方法写入 STDOUT 中的最高分如下格式:最高分是:

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

    My main problem is that the symbol is not defined. I have tried this a bunch of times with no luck. I'm sure it's a fairly easy to fix problem but I could really appreciate some help. Here is my code:

        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
    

    推荐答案

    你应该正确声明你的变量 int z,a,b,c,d,e,f,g; 并计算仅在您读入所有值后 获得最大分数.

    You should declare your variables correctly int z,a,b,c,d,e,f,g; and calculate the max score only after you read in all the values.

    这篇关于Java编译错误:找不到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆