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...
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 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.
in c++ QUESTION 4: Write the code to do the following: -read input from the keyboard...
in c++ QUESTION 4: Write the code to do the following: -read input from the keyboard by displaying the message on the screen to ask and read the following information: * customer ID (string) * customer name (string)                                                        * balance (float) -open output file customer .txt to write -Write to the output file customer.txt the following information:                 Customer ID – customer name – balance For example: 1561175753 - James Smith – 1255.25 -close file QUESTION 5: -create one notepad...
Objectives Ability to receive input from keyboard Use the printf statement as an alternative to cout....
Objectives Ability to receive input from keyboard Use the printf statement as an alternative to cout. Ability to use For loop Ability to use Do-while loop Program 1:                                                                                                                          Create a program called CountUpBy5. Input: The program should accept a positive integer n from the user as input. If the given input is not a positive input it should prompt the user to retry Hint: use a While-loop for this Output: The program should then count all numbers from 0 up...
You are entering a letter ‘B’ from an input device to be displayed on a monitor...
You are entering a letter ‘B’ from an input device to be displayed on a monitor via an 8-bit microcontroller. Describe the steps/processes of the 8-bit microcontroller needs to perform to display the output on the monitor.
Write a C++ function called parse that reads one line of user input from the keyboard...
Write a C++ function called parse that reads one line of user input from the keyboard and creates an array of the strings found in the input.  Your function should be passed the array and a reference variable that is to be assigned the length of the array.  Prompt the user and read the input from within the function. For example:  If the user inputs copy this that, the resulting array would have length 3 and contain the strings “copy”, “this”, and “that”....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT