SHARE
TWEET

04.Group Stage online exam 28 july

shniaga Nov 28th, 2018 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package PBOnlineExamJuly2018;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class GroupStage {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String countryName = scanner.nextLine();
  9.         int gamesToPlay = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int points = 0;
  12.         int playedGames = 0;
  13.         int totalGoalsFor = 0;
  14.         int totalGoalsAgainst = 0;
  15.  
  16.         while (true) {
  17.             if (playedGames == gamesToPlay){
  18.                 break;
  19.             } else {
  20.                 int goalsFor = Integer.parseInt(scanner.nextLine());
  21.                 int goalsAgainst = Integer.parseInt(scanner.nextLine());
  22.                 totalGoalsFor += goalsFor;
  23.                 totalGoalsAgainst += goalsAgainst;
  24.                 playedGames++;
  25.                 if (goalsFor > goalsAgainst) {
  26.                     points += 3;
  27.                 } else if (goalsFor == goalsAgainst) {
  28.                     points++;
  29.                 } else {
  30.                     points -= 3;
  31.                 }
  32.             }
  33.         }
  34.         if (totalGoalsFor >= totalGoalsAgainst) {
  35.             int goalDifference = totalGoalsFor - totalGoalsAgainst;
  36.             System.out.printf("%s has finished the group phase with %d points.%n", countryName, points);
  37.             System.out.printf("Goal difference: %d.", goalDifference);
  38.         } else {
  39.             int goalDiff = totalGoalsFor - totalGoalsAgainst;
  40.             System.out.printf("%s has been eliminated from the group phase.%nGoal difference: %d.", countryName, goalDiff);
  41.         }
  42.  
  43.  
  44.  
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top