Advertisement
veronikaaa86

02. Football Results - for loop

Jun 19th, 2021
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int winCounter = 0;
  8. int lostCounter = 0;
  9. int drawCounter = 0;
  10. for (int i = 1; i <= 3; i++) {
  11. String game = scanner.nextLine();
  12.  
  13. char firstResult = game.charAt(0);
  14. char secondResult = game.charAt(2);
  15.  
  16. if (firstResult > secondResult) {
  17. winCounter++;
  18. } else if (firstResult < secondResult) {
  19. lostCounter++;
  20. } else {
  21. drawCounter++;
  22. }
  23. }
  24.  
  25. System.out.printf("Team won %d games.%n", winCounter);
  26. System.out.printf("Team lost %d games.%n", lostCounter);
  27. System.out.printf("Drawn games: %d%n", drawCounter);
  28. }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement