Can';我无法在EclipseJava中找出这个错误

Can';我无法在EclipseJava中找出这个错误,java,eclipse,Java,Eclipse,当我试图运行代码时,我的程序总是遇到麻烦。我得到了错误“线程中的异常”main“java.lang.error:未解决的编译问题:DfinalResult无法解析为变量”。我试过阅读其他的解决方案,但到目前为止没有成功。任何关于我做错了什么让代码运行的建议。另外,应该注意的是,当我试图从我的一个方法调用println的结果时,就会出现这个问题。 -利亚姆 另外,如果数字现在不起作用,那没关系,因为我无法运行它,所以我无法测试它 import java.util.Scanner; public

当我试图运行代码时,我的程序总是遇到麻烦。我得到了错误“线程中的异常”main“java.lang.error:未解决的编译问题:DfinalResult无法解析为变量”。我试过阅读其他的解决方案,但到目前为止没有成功。任何关于我做错了什么让代码运行的建议。另外,应该注意的是,当我试图从我的一个方法调用println的结果时,就会出现这个问题。 -利亚姆 另外,如果数字现在不起作用,那没关系,因为我无法运行它,所以我无法测试它

import java.util.Scanner;

public class mathMecklenburg {
    
    //note: i have a very good idea don't forget it 

    

    public static void main(String[] args) {

        System.out.println("Enter an integer between 1 and 10 to be used as the first value: ");
        Scanner scanint = new Scanner(System.in);
        int x = scanint.nextInt();
        System.out.println("Enter an integer between 1 and 10 to be used as the second value: ");
        int y = scanint.nextInt();
        System.out.println("Enter an integer between 1 and 10 to be used as the third value: ");
        int z = scanint.nextInt();    //x,y,z will be input values from person
        scanint.close();

        double A1 = operationOne(x);  //A1 is just operation 1 only using x. made double maybe for later difficulty
        System.out.println("The answer to part one of the problems is: " + A1);
        double A2 = operationTwo(x,y); // A2 is operation 2 using x and y
        System.out.println("The answer to part two of the problems is: " + A2);
        double A3 = operationThree(x,y,z); //A3 is operation 3 is using x,y,z. make something difficult here
        System.out.println("The answer to part three of the problems is: " + A3); //these print text then A3 
        int IfinalResult = (int) DfinalResult; 
        System.out.println("The double trouble answer is " + IfinalResult);
        
        
        //summary of the mentioned declared stuff in this part:
        //x,y,z are all input numbers from the person
        //A1, A2, A3 are the holders for each operations output i
        //currently all of them are same data types maybe make more confusing later 

         //final answer should be fun also make a method for final answer later to clean up code
        
        
        // finalAnswer = (Create an equation that utilizes all of the arithmetic operators and all three answers)
          //for me to check that numbers work out
        //System.out.println("The final answer is:" + IfinalResult); //put the result from the final method here for print);        

    }

    //side note: make sure all the first 3 operations give whole numbers no decimals yet 
    public static int operationOne(int x) {

        int answerOne;
        answerOne = x+2;
        // answerOne = (Create an equation that utilizes all of the arithmetic operators with the one input parameter)
        return answerOne;
    }

    public static int operationTwo(int x, int y) {
        int answerTwo;
        answerTwo = x + y;
        // answerOne = (Create an equation that utilizes all of the arithmetic operators with both input parameters)
        return answerTwo;
    }


    public static int operationThree(int x, int y, int z) {
        int answerThree;
        answerThree =  x + y + z;
        // answerThree = (Create an equation that utilizes all of the arithmetic operators using all three input parameters)
        return answerThree;
    }
    
    public static double doubleTrouble(int x, int y, int z, int A1, int A2, int A3, int IfinalResult) { //i thought the method name was funny 
    
    
    double Fx = Math.log(A1 - (A2 + A3)); //oops :) final answer x (Fx) 
    return (int) Fx;
    double Fy = Math.exp(7);  //final answer y (Fy)
    return Fy;
    double Fz = Math.asin(Fy)/(200);  //final answer z (Fz)
    return Fz;
    double Fz1 = Math.exp(Fx+Fy+Fz);
    double F1 = (Fx+Fy+Fz)*(java.lang.Math.PI)+A1; 
    double F2 = F1/(x)+(y)/(x)+5*(x+y);
    double F3 = F1+F2-A1;
    double DfinalResult = F1+F2+2*(F3*Fz1);
    }
    
}
    
doubleTrouble()
方法包含许多错误

  • 不能在两者之间写入
    return
    语句
  • 您没有在main方法中声明
    DfinalResult
    变量
这就是代码没有编译的原因

我已经纠正了这个错误。最新情况:

public class Sample {

    public static void main(String[] args) {

        System.out.println("Enter an integer between 1 and 10 to be used as the first value: ");
        Scanner scanint = new Scanner(System.in);
        int x = scanint.nextInt();
        System.out.println("Enter an integer between 1 and 10 to be used as the second value: ");
        int y = scanint.nextInt();
        System.out.println("Enter an integer between 1 and 10 to be used as the third value: ");
        int z = scanint.nextInt(); // x,y,z will be input values from person
        scanint.close();

        double A1 = operationOne(x); // A1 is just operation 1 only using x. made double maybe for later difficulty
        System.out.println("The answer to part one of the problems is: " + A1);
        double A2 = operationTwo(x, y); // A2 is operation 2 using x and y
        System.out.println("The answer to part two of the problems is: " + A2);
        double A3 = operationThree(x, y, z); // A3 is operation 3 is using x,y,z. make something difficult here
        System.out.println("The answer to part three of the problems is: " + A3); // these print text then A3
        int IfinalResult = (int) doubleTrouble(x, y, z, A1, A2, A3);
        System.out.println("The double trouble answer is " + IfinalResult);
    }

    // side note: make sure all the first 3 operations give whole numbers no
    // decimals yet
    public static int operationOne(int x) {

        int answerOne;
        answerOne = x + 2;
        // answerOne = (Create an equation that utilizes all of the arithmetic operators
        // with the one input parameter)
        return answerOne;
    }

    public static int operationTwo(int x, int y) {
        int answerTwo;
        answerTwo = x + y;
        // answerOne = (Create an equation that utilizes all of the arithmetic operators
        // with both input parameters)
        return answerTwo;
    }

    public static int operationThree(int x, int y, int z) {
        int answerThree;
        answerThree = x + y + z;
        // answerThree = (Create an equation that utilizes all of the arithmetic
        // operators using all three input parameters)
        return answerThree;
    }

    public static double doubleTrouble(int x, int y, int z, double a1, double a2, double a3) {
        double Fx = Math.log(a1 - (a2 + a3)); // oops :) final answer x (Fx)
        double Fy = Math.exp(7); // final answer y (Fy)
        double Fz = Math.asin(Fy) / (200); // final answer z (Fz)
        double Fz1 = Math.exp(Fx + Fy + Fz);
        double F1 = (Fx + Fy + Fz) * (java.lang.Math.PI) + a1;
        double F2 = F1 / (x) + (y) / (x) + 5 * (x + y);
        double F3 = F1 + F2 - a1;
        double DfinalResult = F1 + F2 + 2 * (F3 * Fz1);
        return DfinalResult;
    }

}

变量DfinalResult无法在方法doubleTrouble之外看到,您正在主方法中使用。

您的程序中有4个错误

1:没有调用变量。DfinalResult

2:我不知道你是否知道,但是当你使用return命令时,它不会继续执行代码

public static double doubleTrouble(int x, int y, int z, int A1, int A2, int A3, int IfinalResult) {


double Fx = Math.log(A1 - (A2 + A3)); //oops :) final answer x (Fx) 
return (int) Fx; "Here you return so the next line wouldn't be executed"
double Fy = Math.exp(7);  //final answer y (Fy)
return Fy;
double Fz = Math.asin(Fy)/(200);  //final answer z (Fz)
return Fz;
double Fz1 = Math.exp(Fx+Fy+Fz);
double F1 = (Fx+Fy+Fz)*(java.lang.Math.PI)+A1; 
double F2 = F1/(x)+(y)/(x)+5*(x+y);
double F3 = F1+F2-A1;
double DfinalResult = F1+F2+2*(F3*Fz1);
}

doubletrouble方法写错了。不能返回介于两者之间的值。代码未编译
DfinalResult
未声明为静态变量,因此禁止在
main
方法中引用它。方法
doubleTrouble
return
语句之后出现了太多关于无法访问代码的错误。谢谢!过去我做过很多arduino,但这是我使用java的第一个月。我不知道/可能忘记了那条退货规则。谢谢你帮我清理。这个很好用!我读了一些其他的评论,现在意识到我的错误。感谢您抽出时间来解决这个问题@Liam没问题。我已经改进了我的答案,添加了解释。请看一下这是否可以再次投票。