Advertisement
Spocoman

Favorite Movie

Sep 5th, 2024
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String movie, bestMovie = "";
  7.         int counter = 0, bestAscii = 0;
  8.  
  9.         while (!(movie = scanner.nextLine()).equals("STOP") && ++counter < 7) {
  10.             int currentAscii = 0;
  11.             for (int j = 0; j < movie.length(); j++) {
  12.                 currentAscii += movie.charAt(j);
  13.                 if (movie.charAt(j) > 96 && movie.charAt(j) < 123) {
  14.                     currentAscii -= movie.length() * 2;
  15.                 } else if (movie.charAt(j) > 64 && movie.charAt(j) < 91) {
  16.                     currentAscii -= movie.length();
  17.                 }
  18.             }
  19.             if (currentAscii > bestAscii) {
  20.                 bestAscii = currentAscii;
  21.                 bestMovie = movie;
  22.             }
  23.         }
  24.  
  25.         if (counter == 7) {
  26.             System.out.println("The limit is reached.");
  27.         }
  28.         System.out.println("The best movie for you is " + bestMovie + " with " + bestAscii + " ASCII sum.");
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement