Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Question 9 of the ICSE Specimen Paper 2020.
- * Specimen Paper: http://www.cisce.org/pdf/ICSE-Class-X-Specimen-Question-Papers-2020/Computer%20Applications_Specimen_2020.pdf
- */
- import java.util.Scanner;
- public class Question_9
- {
- static boolean isVowel(char x) //Checks whether a character is an upper case vowel or not.
- {
- boolean check;
- if(x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U')
- check = true;
- else
- check = false;
- return check;
- }
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- String a, pair;
- int i, count = 0;
- char x,y;
- boolean check1, check2;
- System.out.println("Please enter a word / phrase.");
- a = sc.nextLine().toUpperCase(); //Inputing the word / phrase and converting it into upper case.
- System.out.print("Pairs of vowels: ");
- for(i=0;i<a.length()-1;i++)
- {
- x = a.charAt(i);
- y = a.charAt(i+1);
- check1 = isVowel(x);
- if(check1 == true)
- {
- check2 = isVowel(y);
- if(check2 == true)
- {
- pair = Character.toString(x) + Character.toString(y); //String to temporarily store the pairs.
- System.out.print(pair + " | ");
- count++;
- }
- }
- }
- System.out.println();
- System.out.println("Number of pairs: "+count);
- sc.close();
- }
- }
Add Comment
Please, Sign In to add comment