-1
我想要問問四位參賽者的殘疾人隊伍,然後得到總數,如果分數大於32,那麼這是非法的,那麼它是合法的。所有這些都必須在For循環中使用並使用多個方法。下面列出了代碼 。java將不會執行第二種方法
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;
}
}
您需要在'int total = Runner1 + Runner2 + Runner3 + Runner4;'後面調用'Points(total)'並移除此行'System.exit(0);'這會殺死您的JVM,優雅地關閉你的JVM並從main方法中刪除Runner1等的聲明。 – SMA
'for(i = 32; i> = total; i ++)'。再看一遍。你甚至不需要那個循環。 – Tunaki