IvaAnd

FavouriteMovie

Mar 27th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FavouriteMovie {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. String movieTitle = scanner.nextLine();
  9.  
  10. int maxScore = 0;
  11. int counterMovies =0;
  12. String winningMovie = "";
  13.  
  14. for (int movie = 0; movie < 7; movie++) {
  15.  
  16. if (movieTitle.equals("STOP")) {
  17. System.out.printf("The best movie for you is %s with %d ASCII sum.", winningMovie, maxScore);
  18. break;
  19. }
  20. counterMovies++;
  21. int sumChar = 0;
  22. int countCharsInTitle = movieTitle.length();
  23.  
  24. for (int j = 0; j < countCharsInTitle; j++) {
  25.  
  26. char currentChar = movieTitle.charAt(j);
  27. int curChar = currentChar;
  28. sumChar = sumChar + curChar;
  29.  
  30. if (curChar >= 97 && curChar <= 122) {
  31. sumChar = sumChar - (2 * countCharsInTitle);
  32. } else if (curChar >= 65 && curChar <= 90) {
  33. sumChar = sumChar - countCharsInTitle;
  34. }
  35.  
  36. }
  37. if (maxScore < sumChar) {
  38. maxScore = sumChar;
  39. winningMovie = movieTitle;
  40. }
  41. movieTitle = scanner.nextLine();
  42. }
  43. if (counterMovies == 7) {
  44. System.out.println("The limit is reached");
  45. System.out.printf("The best movie for you is %s with %d ASCII sum.", winningMovie, maxScore);
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment