Advertisement
yovkovbpfps

Nested Loops Lab Name Wars

Apr 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Travelling {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String input = scanner.nextLine();
  8. int currentWinnerPoint = 0;
  9. String winnerName = "";
  10.  
  11. while (!"STOP".equals(input)){
  12. int sum = 0;
  13. for (int i = 0; i < input.length(); i++) {
  14. sum += input.charAt(i);
  15. }
  16. if (sum > currentWinnerPoint){
  17. currentWinnerPoint = sum;
  18. winnerName = input;
  19. }
  20. input = scanner.nextLine();
  21. }
  22. System.out.printf("Winner is %s - %d!",winnerName, currentWinnerPoint);
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement