Java 方法没有被正确调用?!卡路里应用程序

Java 方法没有被正确调用?!卡路里应用程序,java,methods,Java,Methods,问题是,当我尝试在gym方法之后调用该方法时,它会创建一个错误 public static int testingMeth(actualIntake) { System.out.println(actualIntake); } 如果我要从主方法中删除gym方法,那么我的所有其他方法都有错误。我不一定需要这个程序的解决方案,但为什么我会收到这些错误?只是想学习和提高!谢谢 换句话说,我可以在健身法之前称之为测试法,效果很好,但为什么不在健身法之后呢?如果我去掉gym方法,程序中的其他方法

问题是,当我尝试在gym方法之后调用该方法时,它会创建一个错误

public static int testingMeth(actualIntake) {
    System.out.println(actualIntake);
}
如果我要从主方法中删除gym方法,那么我的所有其他方法都有错误。我不一定需要这个程序的解决方案,但为什么我会收到这些错误?只是想学习和提高!谢谢


换句话说,我可以在健身法之前称之为测试法,效果很好,但为什么不在健身法之后呢?如果我去掉gym方法,程序中的其他方法会出现多个错误?

如果您看到下面的代码,我可以按任意顺序运行这两个方法,并且工作正常

你需要经历一下

它会帮助你的

    gym (30,40,50,100, actualIntake);
}
testingMeth(actualIntake);
import java.util.Scanner;
公共班机{
公共静态void main(字符串[]args){
//使值更易于更改,并创建全局变量进行比较
扫描仪扫描=新扫描仪(System.in);
System.out.println(“你今天摄入了多少卡路里?>>”;
int-actualIntake=scan.nextInt();
System.out.println(“您的BMR是什么?>>”;
int BMR=scan.nextInt();
scan.close();
//这种方法是赤字的预期
热量计算(实施量,BMR);
//这就是你吃的东西
试验方法(实施方案);
实际成本(实际成本、BMR);
//有蛋白质的健身房
健身房(30、40、50、100、健身);
}
//测试方法
//用户应该遵循的内容
公共静态内部热量计算(内部实现,内部BMR){
内部热量差异=BMR-实际值;
if(热量差异=0){
System.out.println(“预期热量不足应为“+热量差异”);
}
返回热差异;
}
//用户实际做了什么
公共静态int实际值(int现实值、int BMR){
int-deficitCalculation=实际值-BMR;
如果(现实决策>BMR){
println(“你这个肥猪油,别吃得太多了,笨蛋,+”失败的赤字超过“+不足计算+”卡路里“);
}否则,如果(实施决策=50){
System.out.println(“干得好,你在喝蛋白质奶昔时消耗了超过50卡路里”);
}否则如果(总健身房<50){
println(“如果你把卡路里放回脂肪中,喝蛋白质有什么该死的意义:“+totalGym+”卡路里是你损失了多少”);
}
int gymAndTotal=现实决策-总体健身;
System.out.println(“你吃了什么,加上你消耗的蛋白质减去你的锻炼量”+gymAndTotal);
返回体育馆;
}
公共静态无效测试方法(int实现){
System.out.println(实现标记);
}
}
您需要了解,对于
,类/方法/开关案例/或条件的每个开口大括号必须有闭合大括号。

在您的例子中,您试图在关闭类的大括号后调用某个方法,因此这些元素不是类的一部分,这就是它抛出错误的原因。

“我为什么收到这些错误”-您能否编辑问题以包含您看到的错误的详细信息?
testingMeth(RealizationTake)
不在
main
方法的范围内。这些元素不是类的一部分,您的意思是它们不是方法的一部分?另外,我在评论中已经指出了这一点。由于这实际上是一个输入错误,正确的做法是评论和投票,以作为输入错误结束。
public static int testingMeth(actualIntake) {
    System.out.println(actualIntake);
}
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        //making values easier to change and also create global variables for gym comparison

        Scanner scan = new Scanner(System.in);
        System.out.println("How many calories did you consume today?>> ");
        int actualIntake = scan.nextInt();
        System.out.println("What is your BMR?>> ");
        int BMR = scan.nextInt();
        scan.close();

        //this method is what is expected with deficit
        calorieCalculation(actualIntake, BMR);
        //this is what you actually ate
        testingMeth(actualIntake);
        actualCalories(actualIntake, BMR);
        //gym with protein
        gym(30, 40, 50, 100, actualIntake);
    }

    //testing method


    //What the user should be following
    public static int calorieCalculation(int actualIntake, int BMR) {
        int calorieDifference = BMR - actualIntake;

        if (calorieDifference <= 0) {
            calorieDifference = Math.abs(BMR - actualIntake);
            System.out.println("You have went over your deficit, well done fatty = " + calorieDifference);
        } else if (calorieDifference >= 0) {
            System.out.println("Expected calorie deficit should be " + calorieDifference);
        }

        return calorieDifference;
    }

    //What the user actually did
    public static int actualCalories(int actualIntake, int BMR) {

        int deficitCalculation = actualIntake - BMR;
        if (actualIntake > BMR) {
            System.out.println("You fat lard stop overeating you dumbass, " + "failed deficit of over " + deficitCalculation + " Calories.");

        } else if (actualIntake < BMR) {
            System.out.println("Well done you created a deficit of " + deficitCalculation + " keep her going keep her movin.");
        }
        return deficitCalculation;
    }

    //How much did you burn in the gym
    public static int gym(int treadMillCal, int rowingMachineCal, int weightsCal, int proteinShakeCal, int actualIntake) {

        int totalGym = ((treadMillCal + rowingMachineCal + weightsCal) - proteinShakeCal);

        if (totalGym >= 50) {
            System.out.println("Well done you have burned more than 50 calories whilst drinking protein shake");
        } else if (totalGym < 50) {
            System.out.println("Whats the bloody point of drinking protein if your putting the calories back on fatty: " + totalGym + " calories is how much you lost");
        }

        int gymAndTotal = actualIntake - totalGym;
        System.out.println("What you ate, plus minusing your workout along with the protein you consumed " + gymAndTotal);

        return totalGym;
    }

    public static void testingMeth(int actualIntake) {
        System.out.println(actualIntake);
    }

}