[英]java won't seen to execute the second method
我想分別問四名跑者的傷殘等級,然后得到總分,然后,如果分數大於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;
}
}
您不需要四個單獨的跑步者,也刪除 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 方法中完成,但是如果您必須使用單獨的方法。 只需將代碼粘貼在那里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.