Advertisement
Guest User

Untitled

a guest
Aug 1st, 2020
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class theMostpowerfulWord {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String command = scanner.nextLine();
  7.         String word = "";
  8.         int maxSum = Integer.MIN_VALUE;
  9.  
  10.         while (!command.equals("End of words")) {
  11.             int currentSum = 0;
  12.  
  13.             boolean check = false;
  14.             for (int i = 0; i < command.length(); i++) {
  15.                 int ascii = 0;
  16.                 char current = command.charAt(i);
  17.                 ascii = (int) current;
  18.                 currentSum += ascii;
  19.                 boolean isVowel = current == 'a' || current == 'o' || current == 'e' || current == 'i' || current == 'u' || current == 'y' || current == 'A' || current == 'O' || current == 'E' || current == 'I' || current == 'U' || current == 'Y';
  20.                 if (i == 0 && isVowel) {
  21.                     check = true;
  22.                 }
  23.             }
  24.                 if (check) {
  25.                     currentSum = currentSum * command.length();
  26.                 } else {
  27.                     currentSum = currentSum / 3;
  28.                 }
  29.                 if (currentSum > maxSum) {
  30.                     maxSum = currentSum;
  31.                     word = command;
  32.                 }
  33.                 command = scanner.nextLine();
  34.             }
  35.             System.out.printf("The most powerful word is %s - %d", word, maxSum);
  36.         }
  37.     }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement