Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FavouriteMovie {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String movieTitle = scanner.nextLine();
- int maxScore = 0;
- int counterMovies =0;
- String winningMovie = "";
- for (int movie = 0; movie < 7; movie++) {
- if (movieTitle.equals("STOP")) {
- System.out.printf("The best movie for you is %s with %d ASCII sum.", winningMovie, maxScore);
- break;
- }
- counterMovies++;
- int sumChar = 0;
- int countCharsInTitle = movieTitle.length();
- for (int j = 0; j < countCharsInTitle; j++) {
- char currentChar = movieTitle.charAt(j);
- int curChar = currentChar;
- sumChar = sumChar + curChar;
- if (curChar >= 97 && curChar <= 122) {
- sumChar = sumChar - (2 * countCharsInTitle);
- } else if (curChar >= 65 && curChar <= 90) {
- sumChar = sumChar - countCharsInTitle;
- }
- }
- if (maxScore < sumChar) {
- maxScore = sumChar;
- winningMovie = movieTitle;
- }
- movieTitle = scanner.nextLine();
- }
- if (counterMovies == 7) {
- System.out.println("The limit is reached");
- System.out.printf("The best movie for you is %s with %d ASCII sum.", winningMovie, maxScore);
- }
- }
- }
Add Comment
Please, Sign In to add comment