In: Computer Science
Input a phrase from the keyboard. If the last letter in the phrase is "a" or "e" (uppercase or lowercase) then output the last letter 3 times. ELSE If the first letter in the phrase is either "i", "o", or "u" (uppercase or lowercase) then output the length of the phrase In all other cases print "no vowel"
Code language is java
Solution:-
Java Code:-
import java.util.*;
// Main class
public class Main
{
// main method
public static void main(String[] args) {
System.out.print("Enter the phrase: ");
// Instantiate object of Scanner class
Scanner sc = new Scanner(System.in);
// Taking user input of phrase
String phrase = sc.nextLine();
// Computing last index of phrase
int len = phrase.length()-1;
// In case last letter in the phrase is "a" or "e"
(uppercase or lowercase)
if( (phrase.charAt(len) == 'a') || (phrase.charAt(len)
== 'e') ||
(phrase.charAt(len) == 'A') || (phrase.charAt(len) ==
'E') )
{
// Prinitng last letter 3 times
System.out.println(phrase.charAt(len));
System.out.println(phrase.charAt(len));
System.out.println(phrase.charAt(len));
}
// In case last letter in the phrase is "i", "o", or
"u" (uppercase or lowercase)
else if( (phrase.charAt(0) == 'i') ||
(phrase.charAt(0) == 'o') || (phrase.charAt(0) == 'u') ||
(phrase.charAt(0) == 'I') || (phrase.charAt(0) == 'O') ||
(phrase.charAt(0) == 'U') )
{
// Prinitng length of phrase
System.out.println(phrase.length());
}
// In all other cases
else{
System.out.println("no vowel");
}
}
}
Code snapshot:-
Output snapshot:-