galinyotsev123

ProgBasics07Nested-Loops-P07nameWars

Jan 7th, 2019
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P07nameWars {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String currentName = scanner.nextLine();
  8.  
  9. String winerName = " ";
  10. int winnerSum = 0;
  11.  
  12.  
  13. while (!currentName.equalsIgnoreCase("STOP")){
  14.  
  15. int symbolSum = 0;
  16. for (int i = 0; i < currentName.length(); i++) {
  17. char currentSymbol = currentName.charAt(i);
  18.  
  19. if (Character.isAlphabetic(currentSymbol)) {
  20. symbolSum += currentSymbol;
  21. }
  22. }
  23. if (symbolSum > winnerSum) {
  24. winnerSum = symbolSum;
  25. winerName = currentName;
  26. }
  27. currentName = scanner.nextLine();
  28. }
  29. System.out.printf("Winner is %s - %d!", winerName,winnerSum);
  30. }
  31. }
Add Comment
Please, Sign In to add comment