Advertisement
desislava_topuzakova

Untitled

Sep 26th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P06_NameGame {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. String name = scan.nextLine();
  8. int bestPoints = 0;
  9. String winner = "";
  10.  
  11. while (!"Stop".equals(name)) {
  12. int currentPoints = 0;
  13. for (int i = 0; i < name.length(); i++) {
  14. int number = Integer.parseInt(scan.nextLine());
  15. if (number == name.charAt(i)) {
  16. currentPoints += 10;
  17. } else {
  18. currentPoints += 2;
  19. }
  20. }
  21.  
  22. if (currentPoints >= bestPoints) {
  23. bestPoints = currentPoints;
  24. winner = name;
  25. }
  26. name = scan.nextLine();
  27. }
  28. System.out.println(String.format("The winner is %s with %d points!", winner, bestPoints));
  29. }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement