Question

In: Computer Science

Input a phrase from the keyboard. If the last letter in the phrase is "a" or...

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

Solutions

Expert Solution

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:-


Related Solutions

Input a phrase from the keyboard and output whether or not it is a palindrome. For...
Input a phrase from the keyboard and output whether or not it is a palindrome. For example: 1. If the input is Madam I'm Adam Your output should be "Madam, I'm Adam" is a palindrome 2. If your input is Going to the movies? Your output should be "Going to the movies?" is not a palindrome Note the quotes in the output line. Code language java using JGrasp
Input a phrase from the keyboard. For example, input could be: Today is a rainy day,...
Input a phrase from the keyboard. For example, input could be: Today is a rainy day, but the sun is shining. Your program should count (and output) the number of "a"s in the phrase, the number of "e"s, the number of "i"s , the number of "o"s, the number of "u"s, and the total number of vowels. Note: The number of "a"s means the total of uppercase and lowercase "a"s etc. Also: the vowels are a,e,i,o,u. In the above example...
JAVA Input a phrase from the keyboard, if the phrase contains "red" or "RED" print out...
JAVA Input a phrase from the keyboard, if the phrase contains "red" or "RED" print out "red" . if the phrase contains "blue" or "BLUE" output "blue" In all other cases print "No Color" For example: If the input was "Violets are BLUE" your output should be "blue" If the input was "Singing the blues" output "blue" If the input was "I have a pure bred puppy" your output should be "red" If the input was "Today is Monday" output...
def main(): phrase = input('Enter a phrase: ') # take a phrase from user acronym =...
def main(): phrase = input('Enter a phrase: ') # take a phrase from user acronym = '' # initialize empty acronym for word in phrase.split(): # for each word in phrase acronym += word[0].upper() # add uppercase version of first letter to acronym print('Acronym for ' + phrase + ' is ' + acronym) # print results main() The program should then open the input file, treat whatever is on each line as a phrase and make its acronym using...
Write a driver to get a String input from keyboard and if the input string has...
Write a driver to get a String input from keyboard and if the input string has less than 10 characters, throw a StringTooShortException. public class StringTooShortException extends Exception {     //-----------------------------------------------------------------     // Sets up the exception object with a particular message.     //-----------------------------------------------------------------     public StringTooShortException()     {         super("String does not have enough characters");     } }
There is a new input technique for touch-screen devices that allows users to input a word by sliding a finger from letter to letter.
what is the test static? what is the critical value? what is the p value?There is a new input technique for touch-screen devices that allows users to input a word by sliding a finger from letter to letter. The user's finger is only removed from the keyboard between words. The developers claim that typing speed using this new input technique is faster when compared with traditional touch-screen keyboards. The accompanying data table shows the typing speeds of 10 individuals who...
Write a program that prompts the user to input their first name from the keyboard and...
Write a program that prompts the user to input their first name from the keyboard and stores them in the variable "firstName". It does the same for last name and stores it in the variable "lastName". It then uses strcat to merge the two names, separates them by a space and stores the full name into a string variable called "fullName". In the end, the program must print out the string stored within fullName. ANSWER IN C LANGUAGE ! You...
Write a C++ program that takes input from the keyboard of the 3 dimensions of a...
Write a C++ program that takes input from the keyboard of the 3 dimensions of a room (W,L,H in feet) and calculates the area (square footage) needed to paint the walls only. Use function overloading in your program to pass variables of type int and double. You should have two functions: one that accepts int datatypes and one that accepts double datatypes. Also assume a default value of 8 if the height parameter is omitted when calling the functions.
Write below in Python Get user name from keyboard using input() function (Example username = input("Enter...
Write below in Python Get user name from keyboard using input() function (Example username = input("Enter username:") A: What is your name? B: My name is XXXX. B: What is yours? A: My name is XXXX. A: Nice to meet you. B: Nice to meet you, too. Use print statement and use input() function
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and...
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and stores the even integers of num1 in another arraylist named evennum.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT