Advertisement
Valantina

TheMostPowerfulWord /Ex/Java

Jul 9th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P06_TheMostPowerfulWord {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         String mostPowerfulWord = "";
  8.         double maxPower = 0;
  9.  
  10.         String input = "";
  11.         while (!"End of words".equals(input = scan.nextLine())) {
  12.             double inputSum = 0;
  13.             for (int i = 0; i < input.length(); i++) {
  14.                 inputSum += input.charAt(i);
  15.             }
  16.  
  17.             int numLength = input.length();
  18.             String firstLetter = input.toLowerCase();
  19.             if (firstLetter.charAt(0) == 'a'
  20.                     || firstLetter.charAt(0) == 'e'
  21.                     || firstLetter.charAt(0) == 'i'
  22.                     || firstLetter.charAt(0) == 'o'
  23.                     || firstLetter.charAt(0) == 'u'
  24.                     || firstLetter.charAt(0) == 'y') {
  25.                 inputSum = inputSum * numLength;
  26.             } else {
  27.                 inputSum = Math.floor(inputSum / numLength);
  28.             }
  29.  
  30.  
  31.             if (inputSum > maxPower) {
  32.                 maxPower = inputSum;
  33.                 mostPowerfulWord = input;
  34.             }
  35.         }
  36.  
  37.         System.out.println(String.format("The most powerful word is %s - %.0f", mostPowerfulWord, maxPower));
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement