Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ExamPractice;
- import java.util.Scanner;
- public class BasketballTournaments_06 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String tournament = scanner.nextLine();
- int ownPoints = 0;
- int gainPoints = 0;
- int gamesCounter = 0;
- int totalWonGames = 0;
- int totalLostGames = 0;
- while (!tournament.equals("End of tournaments")) {
- int numGames = Integer.parseInt(scanner.nextLine());
- gamesCounter += numGames;
- for (int i = 1; i <= numGames; i++) {
- int pointsOwn = Integer.parseInt(scanner.nextLine());
- int pointsGain = Integer.parseInt(scanner.nextLine());
- if (pointsGain > pointsOwn) {
- totalLostGames++;
- gainPoints = pointsGain - pointsOwn;
- System.out.printf("Game %d of tournament %s: lost with %d points.%n",i,tournament, gainPoints);
- } else {
- totalWonGames++;
- ownPoints = pointsOwn - pointsGain;
- System.out.printf("Game %d of tournament %s: win with %d points.%n", i,tournament, ownPoints);
- }
- }
- tournament = scanner.nextLine();
- }
- double wonGamesPercent = 1.0 * totalWonGames / gamesCounter * 100;
- double lostGamesPercent = 1.0 * totalLostGames / gamesCounter * 100;
- System.out.printf("%.2f%% matches win", wonGamesPercent);
- System.out.printf("%.2f%% matches lost", lostGamesPercent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement