Java 爪哇元';我没有看到执行第二种方法
我想问一下由四名运动员组成的团队各自的伤残等级,然后得到总数。然后,如果分数超过32分,那么这是非法的,如果没有,那么这是合法的。所有这些都必须在For循环中完成,并使用多个方法。 下面列出了代码Java 爪哇元';我没有看到执行第二种方法,java,for-loop,Java,For Loop,我想问一下由四名运动员组成的团队各自的伤残等级,然后得到总数。然后,如果分数超过32分,那么这是非法的,如果没有,那么这是合法的。所有这些都必须在For循环中完成,并使用多个方法。 下面列出了代码 public class Runner11 { public static void main(String[] p) { int Points; int total = DisabilityClass(); int Runner1;
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;
}
}
您不需要四个独立的运行程序,也可以删除系统。退出(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;
}
int runner=0;
int-total=0;
对于(int i=0;i您需要在int total=Runner1+Runner2+Runner3+Runner4;
之后调用Points(total)
,然后删除这一行System.exit(0);
,这会杀死您的JVM,无论如何都会优雅地关闭JVM,并从主方法中删除Runner1等的声明。for(i=32;i>=total;i++)
。再看看这个。你甚至不需要那个循环。
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");
}