Question

In: Computer Science

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 your output should be:

The phrase is "Today is a rainy day, but the sun is shining."

The number of a's: 4

The number of e's: 1

The number of i's: 5

The number of o's: 1

The number of u's: 2

The total number of vowels is: 13

Code language: java

Solutions

Expert Solution

Code:

import java.util.*;
class Vowel{
   public static void main(String[] args) {
       Scanner s =new Scanner(System.in);
       System.out.println("Enter a phrase");
       String str=s.nextLine();
       int no_a=0;
       int no_e=0;
       int no_i=0;
       int no_o=0;
       int no_u=0;
       int total=0;

       for(int i=0;i<str.length();i++){
           if(((str.charAt(i))=='a')||((str.charAt(i))=='A')){
               no_a++;
               total++;
           }
           else if(((str.charAt(i))=='e')||((str.charAt(i))=='E')){
               no_e++;
               total++;
           }
           else if(((str.charAt(i))=='i')||((str.charAt(i))=='I')){
               no_i++;
               total++;
           }else if(((str.charAt(i))=='o')||((str.charAt(i))=='O')){
               no_o++;
               total++;
           }else if(((str.charAt(i))=='u')||((str.charAt(i))=='U')){
               no_u++;
               total++;
           }
           else{
               //do nothing

           }
          

       }
           System.out.println("The number of a's: "+no_a);
           System.out.println("The number of e's: "+no_e);
           System.out.println("The number of i's: "+no_i);
           System.out.println("The number of o's: "+no_o);
           System.out.println("The number of u's: "+no_u);
           System.out.println("Total Vowels are: "+total);


   }
}

Output:

Code Screenshot:

Code snippet:

//as we are using scanner 
import java.util.*;
//class name is Vowel
class Vowel{
        public static void main(String[] args) {
                Scanner s =new Scanner(System.in);
                System.out.println("Enter a phrase");
                //taking input
                String str=s.nextLine();
                //initializing all vowel counts
                int no_a=0;
                int no_e=0;
                int no_i=0;
                int no_o=0;
                int no_u=0;
                int total=0;

                //a loop that traverses the string
                for(int i=0;i<str.length();i++){
                        //if the character is a
                        if(((str.charAt(i))=='a')||((str.charAt(i))=='A')){
                                no_a++;
                                total++;
                        }
                        //if it is e
                        else if(((str.charAt(i))=='e')||((str.charAt(i))=='E')){
                                no_e++;
                                total++;
                        }
                        //if it is i
                        else if(((str.charAt(i))=='i')||((str.charAt(i))=='I')){
                                no_i++;
                                total++;
                        }
                        //if it is o
                        else if(((str.charAt(i))=='o')||((str.charAt(i))=='O')){
                                no_o++;
                                total++;
                        }
                        //if it is u
                        else if(((str.charAt(i))=='u')||((str.charAt(i))=='U')){
                                no_u++;
                                total++;
                        }
                        else{
                                //do nothing

                        }
                        

                }
                        System.out.println("The number of a's: "+no_a);
                        System.out.println("The number of e's: "+no_e);
                        System.out.println("The number of i's: "+no_i);
                        System.out.println("The number of o's: "+no_o);
                        System.out.println("The number of u's: "+no_u);
                        System.out.println("Total Vowels are: "+total);


        }
}

Related Solutions

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
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
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");     } }
Rainy Day Company The Business Situation Rainy Day Company manufactures a unique umbrella. The company began...
Rainy Day Company The Business Situation Rainy Day Company manufactures a unique umbrella. The company began operations April 1, 2020. Its accountant quit the second week of operations, and the company is searching for a replacement. The company has decided to test the knowledge and ability of all candidates interviewing for the position. Each candidate will be provided with the information below and then asked to prepare a series of reports, schedules, budgets, and recommendations based on that information. The...
Rainy Day Company The Business Situation Rainy Day Company manufactures a unique umbrella. The company began...
Rainy Day Company The Business Situation Rainy Day Company manufactures a unique umbrella. The company began operations April 1, 2020. Its accountant quit the second week of operations, and the company is searching for a replacement. The company has decided to test the knowledge and ability of all candidates interviewing for the position. Each candidate will be provided with the information below and then asked to prepare a series of reports, schedules, budgets, and recommendations based on that information. The...
Rainy Day Company The Business Situation Rainy Day Company manufactures a unique umbrella. The company began...
Rainy Day Company The Business Situation Rainy Day Company manufactures a unique umbrella. The company began operations April 1, 2020. Its accountant quit the second week of operations, and the company is searching for a replacement. The company has decided to test the knowledge and ability of all candidates interviewing for the position. Each candidate will be provided with the information below and then asked to prepare a series of reports, schedules, budgets, and recommendations based on that information. The...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT