简体   繁体   English

无法在 Eclipse Java 中找出这个错误

[英]Can't figure out this Error in Eclipse Java

My program keeps hitting a brickwall when I try to run the code.当我尝试运行代码时,我的程序一直在碰壁。 I get the error "Exception in thread "main" java.lang.Error: Unresolved compilation problem: DfinalResult cannot be resolved to a variable".我收到错误“线程“main”java.lang.Error 中的异常:未解决的编译问题:DfinalResult 无法解析为变量”。 I have tried to read other solutions but so far no luck.我曾尝试阅读其他解决方案,但到目前为止还没有运气。 Any adivce on what im doing wrong to get this code to run.关于我做错了什么来运行此代码的任何建议。 Also, it should be noted that the issue occurs when I try to call the result from one of my methods to a println.另外,应该注意的是,当我尝试将结果从我的方法之一调用到 println 时会出现问题。 -Liam Ps If the numbers dont work out right now that's okay I havent been able to test it since I cant run it lol. -Liam Ps 如果数字现在不计算,那没关系,因为我无法运行它,所以我无法对其进行测试,哈哈。

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 之外无法看到变量 DfinalResult 并且您正在主方法中使用。

there is 4 errors in your program你的程序有 4 个错误

1: there is no variable called. 1:没有调用变量。 DfinalResult最终结果

2: I don't know if you know but when you use the command return it dosn't continue with the code 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() method contains a lot of errors. doubleTrouble()方法包含很多错误。

  • You can't write return statements in between.您不能在两者之间编写return语句。
  • You didn't declare DfinalResult variable in the main method.您没有在 main 方法中声明DfinalResult变量。

That's why the code didn't compile.这就是代码没有编译的原因。

I have fixed the error.我已经修复了错误。 Update to this :更新到这个:

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;
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM