Advertisement
stoyanoff

FootballResults-While

Jun 16th, 2020
1,175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Test {
  4.     public static void main(String[] args) {
  5.        Scanner myScan = new Scanner(System.in);
  6.         String result;
  7.         int won = 0;
  8.         int lost = 0;
  9.         int draw = 0;
  10.  
  11.  
  12.  
  13.         while (true) {
  14.             result = myScan.nextLine();
  15.             if(result.equals("End")) {
  16.                 break;
  17.             }
  18.             int teamHome = Integer.parseInt(result.charAt(0) + "");
  19.             int teamAway = Integer.parseInt(result.charAt(2) + "");
  20.             if (teamHome > teamAway) {
  21.                 won++;
  22.             } else if (teamHome == teamAway) {
  23.                 draw++;
  24.             }   else {
  25.                 lost++;
  26.             }
  27.  
  28.  
  29.         }
  30.  
  31.         System.out.printf("Team won %d games.\n", won);
  32.         System.out.printf("Team lost %d games.\n", lost);
  33.         System.out.printf("Drawn games: %d", draw);
  34.  
  35.  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement