Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String movie, bestMovie = "";
- int counter = 0, bestAscii = 0;
- while (!(movie = scanner.nextLine()).equals("STOP") && ++counter < 7) {
- int currentAscii = 0;
- for (int j = 0; j < movie.length(); j++) {
- currentAscii += movie.charAt(j);
- if (movie.charAt(j) > 96 && movie.charAt(j) < 123) {
- currentAscii -= movie.length() * 2;
- } else if (movie.charAt(j) > 64 && movie.charAt(j) < 91) {
- currentAscii -= movie.length();
- }
- }
- if (currentAscii > bestAscii) {
- bestAscii = currentAscii;
- bestMovie = movie;
- }
- }
- if (counter == 7) {
- System.out.println("The limit is reached.");
- }
- System.out.println("The best movie for you is " + bestMovie + " with " + bestAscii + " ASCII sum.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement