package toto.com;
import java.util.Scanner;
public class redactor {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String tournament = scanner.nextLine();
double won = 0;
double lost = 0;
double receptacle = 0;
//Input
//Ballers
//3
//87
//63
//56
//65
//75
//64
//Sharks
//4
//64
//76
//65
//86
//68
//99
//45
//78
//End of tournaments
// the output is at the bottom
while (!tournament.equals("End of tournaments")) {
int matches = Integer.parseInt(scanner.nextLine());
receptacle += matches;
for (int i = 0; i < matches; i++) {//TODO redact of needed to 0 and <
int points1 = Integer.parseInt(scanner.nextLine());
int points2 = Integer.parseInt(scanner.nextLine());
if (points1 > points2) {
won++;
System.out.printf("%nGame %d of tournament %s: win with %d points.", i, tournament, points1 - points2);
} else {
lost++;
System.out.printf("%nGame %d of tournament %s: lost with %d points.", i, tournament, points2 - points1);
}
}
System.out.printf("%n%.2f%% matches win%n" +
"%.2f%% matches lost", (won / receptacle) * 100, (lost / receptacle) * 100); // As far as I'm concerned printing it outside of the loop using if statement doesnt't seem to work because the condition within is always true.
tournament = scanner.nextLine();
}
}
}
//Desired Output
//Game 1 of tournament Ballers: win with 24 points.
//Game 2 of tournament Ballers: lost with 9 points.
//Game 3 of tournament Ballers: win with 11 points.
//Game 1 of tournament Sharks: lost with 12 points.
//Game 2 of tournament Sharks: lost with 21 points.
//Game 3 of tournament Sharks: lost with 31 points.
//Game 4 of tournament Sharks: lost with 33 points.
//28.57% matches win
//71.43% matches lost
1条答案
按热度按时间vojdkbi01#
我把你的问题理解为问如何在比赛结束后才打印输赢数字。要完成此操作,请在while循环之后移动最后一个printf语句。那么它只会在你的比赛结束后运行一次。
输出