Guest User

ICSE Specimen Paper 2020 - Question 9.

a guest
Oct 29th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. /**
  2.  * Question 9 of the ICSE Specimen Paper 2020.
  3.  * Specimen Paper: http://www.cisce.org/pdf/ICSE-Class-X-Specimen-Question-Papers-2020/Computer%20Applications_Specimen_2020.pdf
  4.  */
  5. import java.util.Scanner;
  6. public class Question_9
  7. {
  8.     static boolean isVowel(char x) //Checks whether a character is an upper case vowel or not.
  9.     {
  10.         boolean check;
  11.        
  12.         if(x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U')
  13.             check = true;
  14.         else
  15.             check = false;
  16.        
  17.         return check;
  18.     }
  19.     public static void main(String[] args)
  20.     {
  21.         Scanner sc = new Scanner(System.in);
  22.         String a, pair;
  23.         int i, count = 0;
  24.         char x,y;
  25.         boolean check1, check2;
  26.        
  27.         System.out.println("Please enter a word / phrase.");
  28.         a = sc.nextLine().toUpperCase(); //Inputing the word / phrase and converting it into upper case.
  29.        
  30.         System.out.print("Pairs of vowels: ");
  31.        
  32.         for(i=0;i<a.length()-1;i++)
  33.         {
  34.             x = a.charAt(i);
  35.             y = a.charAt(i+1);
  36.             check1 = isVowel(x);
  37.             if(check1 == true)
  38.             {
  39.                 check2 = isVowel(y);
  40.                 if(check2 == true)
  41.                 {
  42.                     pair = Character.toString(x) + Character.toString(y); //String to temporarily store the pairs.
  43.                     System.out.print(pair + " | ");
  44.                     count++;
  45.                 }  
  46.             }
  47.         }
  48.        
  49.         System.out.println();
  50.         System.out.println("Number of pairs: "+count);
  51.         sc.close();
  52.     }
  53. }
Add Comment
Please, Sign In to add comment