Question

In: Computer Science

Instructions: Create a Java program that reads a string entered by the user and then determines...

Instructions: Create a Java program that reads a string entered by the user and then determines and prints how many of each lowercase vowel (a, e, i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also, count and print the number of non-vowel characters.

Example: User enters: "This house is beautiful."

a: 1

e: 2

i: 3

o: 1

u: 2

non-vowel:10

Solutions

Expert Solution

The Solution:

import java.util.Scanner; //for accepting input
public class Main
{
   public static void main(String[] args) {
   //inntializing variables for count n input string
int aCount = 0, eCount = 0, iCount = 0;
int oCount = 0, uCount = 0, nonVowelCount = 0;
String userString;
  
//getting the string from user
Scanner sc = new Scanner (System.in);
System.out.println("Enter a string:");
userString = sc.nextLine();
  
for (int i = 0; i < userString.length(); i++) {
//reach each character of string and checking
char ch = userString.charAt(i);
  
if (ch== 'a') aCount++; //checking vowel 'a'   
else if (ch== 'e') eCount++; //checking vowel 'e'
else if (ch== 'i') iCount++; //checking vowel 'i'
else if (ch== 'o') oCount++; //checking vowel 'o'
else if (ch== 'u') uCount++; //checking vowel 'u'
//checking non-vowels
else if ((ch >= 'a'&& ch <= 'z')||(ch >= 'A'&& ch <= 'Z')) nonVowelCount++;   
}
  
//displaying the count of each vowel and non-vowels
System.out.println("a: " + aCount + "\n" +
"e: " + eCount + "\n" +
"i: " + iCount + "\n" +
"o: " + oCount + "\n" +
"u: " + uCount + "\n" +
"non-vowel:" + nonVowelCount);
}
}

The Screenshots:

The Code:

The Output:


Related Solutions

(JAVA) Write an application that reads three nonzero values entered by the user and determines and...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Enter three sizes, separated by spaces(decimals values are acceptable): 4.5·5.5·3.5 A triangle could measure 4.50, 5.50, by 3.50.
Write a java program using the following instructions: Write a program that determines election results. Create...
Write a java program using the following instructions: Write a program that determines election results. Create two parallel arrays to store the last names of five candidates in a local election and the votes received by each candidate. Prompt the user to input these values. The program should output each candidates name, the votes received by that candidate, the percentage of the total votes received by the candidate, and the total votes cast. Your program should also output the winner...
using java language "Data Structures" I have to write program which stores string entered by user...
using java language "Data Structures" I have to write program which stores string entered by user into cursor array implementation here is the code public static void main(String[] args) { CursorArray sorted =new CursorArray();//the strings must added here how can i store them                  String []inputs = new String[50];                   for (int i=0; i< 50; i++) {            System.out.println("Enter the words you want to sort and use exit to stop");...
1) Create a "Can I be President?" program. The program determines if the user meets the...
1) Create a "Can I be President?" program. The program determines if the user meets the minimum requirements for becoming the President of the United States. Use user input. The rules for being president of the U.S. are: Older than 35 Resident of US for 14 Years Natural born citizen Print True if the person could be president and False if they can't be president. 2) Alter one line of that program to be a "I can't be President?" game....
Write Java program Lab52.java which reads in a line of text from the user. The text...
Write Java program Lab52.java which reads in a line of text from the user. The text should be passed into the method: public static String[] divideText(String input) The "divideText" method returns an array of 2 Strings, one with the even number characters in the original string and one with the odd number characters from the original string. The program should then print out the returned strings.
(JAVA) We will write a program to check the spelling of the word entered by user,...
(JAVA) We will write a program to check the spelling of the word entered by user, using data from a dictionary, which is text file. The program will ask user to enter a word for spell check, and then check in the text file (dictionary.txt) if the word exists. (The dictionary.txt file is provided) If the word exists in text file, the output will be “Word is correctly spelled”. If the word doesn’t exist in the text file, program will...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Write a Java program that reads an input graph data from a user. Then, it should...
Write a Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2 0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT