Advertisement
Spocoman

The Most Powerful Word

Sep 10th, 2024
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 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 word, vowels = "aeiouyAEIOUY",
  7.                 strongWord = "";
  8.         double strongSum = 0;
  9.  
  10.         while (!(word = scanner.nextLine()).equals("End of words")) {
  11.             double wordSum = 0;
  12.             for (int i = 0; i < word.length(); i++) {
  13.                 wordSum += word.charAt(i);
  14.             }
  15.  
  16.             if (vowels.contains(String.valueOf(word.charAt(0)))) {
  17.                 wordSum *= word.length();
  18.             } else {
  19.                 wordSum /= word.length();
  20.             }
  21.  
  22.             if (wordSum > strongSum) {
  23.                 strongWord = word;
  24.                 strongSum = wordSum;
  25.             }
  26.         }
  27.  
  28.         System.out.println("The most powerful word is " + strongWord + " - " + (int) strongSum);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement