Advertisement
desislava_topuzakova

6. Favorite Movie

Oct 18th, 2022
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Demo {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String input = scanner.nextLine();
  8.  
  9. String movie = "";
  10. int best = 0;
  11. int count = 0;
  12.  
  13. while (!input.equals("STOP")){
  14. count++;
  15. int temp = 0;
  16. for (int i = 0; i < input.length() ; i++) {
  17. int value = (int)input.charAt(i);
  18.  
  19. if (value >= 65 && value <= 90){
  20. value -= input.length();
  21. } else if (value >= 97 && value <= 122){
  22. value -= input.length() * 2 ;
  23. }
  24. temp += value;
  25. }
  26.  
  27. if (temp > best){
  28. best = temp;
  29. movie = input;
  30. }
  31. if (count == 7) {
  32. System.out.println("The limit is reached.");
  33. break;
  34. }
  35. input = scanner.nextLine();
  36. }
  37.  
  38. System.out.printf("The best movie for you is %s with %d ASCII sum.",movie,best);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement