简体   繁体   English

java不会看到执行第二种方法

[英]java won't seen to execute the second method

I suppose to ask the team of four runners individually for their disability class and then get the total of then, afterwards, if the score is greater than 32 it is illegal if not, then it is legal.我想分别问四名跑者的伤残等级,然后得到总分,然后,如果分数大于32则是非法的,否则就是合法的。 all that has to be done in For Loops and using more than one methods.所有这些都必须在 For 循环中完成并使用不止一种方法。 the code is listed down below.下面列出了代码。

public class Runner11 {
    public static void main(String[] p) {
        int Points;
        int total = DisabilityClass();
        int Runner1;
        int Runner2;
        int Runner3;
        int Runner4;
        System.exit(0);
    }

    public static int DisabilityClass() {
        Scanner Scanner = new Scanner(System.in);
        System.out.println("What is the disability class of Runner 1?");
        int Runner1 = Scanner.nextInt();
        System.out.println("What is the disability class of Runner 2?");
        int Runner2 = Scanner.nextInt();
        System.out.println("What is the disability class of Runner 3?");
        int Runner3 = Scanner.nextInt();
        System.out.println("What is the disability class of Runner 4?");
        int Runner4 = Scanner.nextInt();
        int total = Runner1 + Runner2 + Runner3 + Runner4;
        return total;
   }

    public static void Points(int total) {
        int i;
        for(i=32; i >= total; i++) {
            System.out.println("That team has "+total+" points so it's legal");
        }
        return;
    }
}

You do not need the four separate runners, also remove the System.exit(0).您不需要四个单独的跑步者,也删除 System.exit(0)。 also you declare a second set of runners in your disability class.您还宣布了您的残疾级别的第二组跑步者。 Remove all the runners and try this code inside your disability class删除所有跑步者并在您的残疾课程中尝试此代码

int runner = 0;
int total = 0;

for(int i = 0; i<4; i++){
    System.out.println("What is the disability class");
    runner = sc.nextInt();
    total +=runner;
}

Use this code in your points method.在您的积分方法中使用此代码。

if(total<=32){
      System.out.println("That team has "+total+" points so it's legal")
}else{
      System.out.println("That team has "+total+" points so it's illegal");
}

All this can be done in the main method, however if you have to use separate methods.所有这些都可以在 main 方法中完成,但是如果您必须使用单独的方法。 just paste the code in there.只需将代码粘贴在那里。

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

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