du4ko

SumOfVowels

May 26th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1.  
  2. //Your task is to extract the meaning of some movie lines. The messages are actually codes that can be extracted by summing the secret //values of every vowel in the message. The values of the vowels are as follows: A = 65, E = 69, I = 73, O = 79, U = 85. The values apply for both upper and lowercase letters. For example, ‘I am Batman!’ has a total of 4 vowels: three times ‘A’ and one time ‘I’ andtheir //sum is: 3 * 65 + 1 * 73 = 268.
  3.  
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class Iluminati {
  8.  
  9.     public static void main(String[] args) {
  10.         Scanner scan = new Scanner(System.in);
  11.         String text = scan.nextLine();
  12.         text = text.toUpperCase();
  13.         char[] textArray = text.toCharArray();
  14.         int counter = 0;
  15.         int sumOfVows = 0;
  16.         for (int i = 0; i < textArray.length; i++) {
  17.             if (textArray[i] == 'A') {
  18.                 counter++;
  19.                 sumOfVows+=65;
  20.             }
  21.             if (textArray[i] == 'E') {
  22.                 counter++;
  23.                 sumOfVows+=69;
  24.             }
  25.             if (textArray[i] == 'I') {
  26.                 counter++;
  27.                 sumOfVows+=73;
  28.             }
  29.             if (textArray[i] == 'O') {
  30.                 counter++;
  31.                 sumOfVows+=79;
  32.             }
  33.             if (textArray[i] == 'U') {
  34.                 counter++;
  35.                 sumOfVows+=85;
  36.             }
  37.         }
  38.         System.out.println(counter);
  39.         System.out.println(sumOfVows);
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment