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

时间:2016-10-02 12:51:48

标签: java for-loop

我想要让四个跑步者的团队单独参加他们的残疾分类,然后获得总数,之后,如果分数大于32则不合法,那么这是合法的。所有必须在For循环中完成并使用多种方法。 代码列在下面。

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

1 个答案:

答案 0 :(得分:0)

您不需要四个单独的运行程序,也删除System.exit(0)。你也在残疾人阶级宣布第二套跑步者。删除所有参赛者并在您的残疾人课程中尝试此代码

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

在您的积分方法中使用此代码。

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

所有这些都可以在main方法中完成,但是如果必须使用单独的方法。只需将代码粘贴在那里。