Advertisement
Guest User

Untitled

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