Question

Hello, I have a assignment where the user inputs a word and the out will then...

Hello, I have a assignment where the user inputs a word and the out will then tell the user how many of the five vowels are in the word so for example if I typed the word hello, it would output {0 1 0 0 0 } since there is only one vowel and that is e which is in the second row, I have most of it done, but I can't seem to figure out how to get the final part to work basically I need to make it so it will keep asking the user to Enter a string until I type STOP. I need it so it keeps asking to enter a string.

Tldr; I basically need my program to keep asking the user to enter a string, and to keep doing that until stop is typed in all upper case.

public static void main(String args[]){

Scanner keyboard= new Scanner(System.in);
System.out.println("Enter string ");
String input;
input = keyboard.next();
String test = input;
int[] vowels = vowelCount(input);
  
while (!"STOP".equals(input)){
input = keyboard.next();

System.out.print("{");
for(int i=0; i<5; i ++) {
System.out.print(vowels[i] + " ");

}
System.out.print("}");
}   
}

static int[] vowelCount(String str) {
int vowels [] = new int[5];
str = str.toLowerCase();
for (int i = 0; i < str.length(); i++) {
if ((str.charAt(i) == 'a'))
vowels[0]++;
if ((str.charAt(i) == 'e'))
vowels[1]++;
if ((str.charAt(i) == 'i'))
vowels[2]++;
if ((str.charAt(i) == 'o'))
vowels[3]++;
if ((str.charAt(i) == 'u'))
vowels[4]++;
}
return vowels;
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new java program with name "Main.java" is created, which contains following code.

Main.java :

import java.util.*;//import package
public class Main//Class
{ //main method
public static void main(String args[]){
//creating object of Scanner class
Scanner keyboard= new Scanner(System.in);
System.out.println("Enter string ");//asking user to enter string
String input= keyboard.next();//reading string
//using while loop to check whether STOP is the string
while (!"STOP".equals(input)){
int[] vowels = vowelCount(input);//calling function to check number of vowels
System.out.print("{");//used to print {
for(int i=0; i<5; i ++) { //for loop will goes till 5
System.out.print(vowels[i] + " ");//print vowels count
}
System.out.print("}");//print }
System.out.println();//used for blank line
System.out.println("Enter string ");//again asking user to enter string
input = keyboard.next();//reading string
}   
}
//method to count number of vowels
static int[] vowelCount(String str) {
int vowels [] = new int[5];//creating array to store vowels count
str = str.toLowerCase();//converting string to LowerCase
//using for loop that will goes till length of string
for (int i = 0; i < str.length(); i++) {
if ((str.charAt(i) == 'a'))//checking for a
vowels[0]++;//increment a's count
if ((str.charAt(i) == 'e'))//checking for e
vowels[1]++;//increment e's count
if ((str.charAt(i) == 'i'))//checking for i
vowels[2]++;//increment i's count
if ((str.charAt(i) == 'o'))//checking for o
vowels[3]++;//increment o's count
if ((str.charAt(i) == 'u'))//checking for u
vowels[4]++;//increment u's count
}
return vowels;//return array of vowels
}
}

======================================================

Output : Compile and Run above program to get the screen as shown below

Screen 1 :Main.java

Enter string HEEOO 10 2 0 2 0 Enter string Pink 10 0 1 0 0 Enter string STOP . .Program finished with exit code 0 Press ENTER

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Hello, I have a assignment where the user inputs a word and the out will then...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Here is my code to put a quote down, flip it, and reverse it. I do...

    Here is my code to put a quote down, flip it, and reverse it. I do not have much knowledge on coding. Does my code only use Variables, Console I/O, Java Program Design, Intro to IDEs, If Statements, Selection and Conditional Logic, Strings, Loops, Nesting, and Iteration? If not, could it be fixed to only use them? These are the offical steps of the assignment: - Ask a user to enter a quote - whether it's several sentences or a...

  • Hello! I have a Java homework question that I could really use some help with. I...

    Hello! I have a Java homework question that I could really use some help with. I keep getting an error, but I don't know what is wrong with my code. Thanks so much in advance! The problem is: 6.9: VowelAnalyst Design and implement an application that reads a string from the user, 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....

  • JAVA: Excerpt B.A: Complete the implementation of the following method. The purpose of this method is...

    JAVA: Excerpt B.A: Complete the implementation of the following method. The purpose of this method is to return true if and only if all the elements in the array are x. In other words, all elements in the array are the value x (replace -a- with right answer). public static -a- allSame(int[] nums, int x){ for (int i = 0; i < -a-; i++){ if (nums[i] -a- x){ return -a-; } } return -a- } Excerpt B.B: What is printed...

  • Write a program that prompts the user to input a string. The program then uses the...

    Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. #include <iostream> #include <string> using namespace std; void removeVowels(string& str); bool isVowel(char ch);...

  • in order to answer this question their is another two questions I posted  that relate so please...

    in order to answer this question their is another two questions I posted  that relate so please check but they are all one Part 1: Write a method with the signature public static int charAt(String str, int position) o Assume the String str consists of lower-case characters o if position <str.length the method returns the ascii value of str.charAt(position) - 96 o if position > str.length the method returns 0.

  • Trying to practice this assignment Argument list: the *yahoonews.txt Data file: yahoonews.txt Wr...

    Trying to practice this assignment Argument list: the *yahoonews.txt Data file: yahoonews.txt Write a program named WordCount.java, in this program, implement two static methods as specified below: public static int countWord(Sting word, String str) this method counts the number of occurrence of the word in the String (str) public static int countWord(String word, File file) This method counts the number of occurrence of the word in the file. Ignore case in the word. Possible punctuation and symbals in the file...

  • I am creating a program where a user will enter in a price amount. And then...

    I am creating a program where a user will enter in a price amount. And then the program will determine how many 20, 10, 5, 1, etc.. they get back. I keep getting "error: unexpected type" in my findValue method. Not too sure why I am getting this. There also might be more bugs in there that I am not aware of because it wont compile. Any help is appreciated. Here is my code: import java.util.Scanner; public class prac1 {...

  • Create a java class that user put two inputs and first input generate n length array...

    Create a java class that user put two inputs and first input generate n length array of randomly generated numbers. and the second input changes that number of multiples in the array into zero. for example, if the user puts 3 and 5 then it generates 34 60 10 and since the second input is 5 then the multiple of 5 eliminates so it generates 34 0 0 here is the main method that I'm going to use class Main...

  • JAVA CODE String[] str = in.nextLine().split("\\s"); for(int i=0;i<=str.length;i++){ if (str[i].equals(stop)) break;    if(i%2==0){ System.out.print(str[i]+" "); }...

    JAVA CODE String[] str = in.nextLine().split("\\s"); for(int i=0;i<=str.length;i++){ if (str[i].equals(stop)) break;    if(i%2==0){ System.out.print(str[i]+" "); }    } lets say the INPUT for the array is: girl, boy, man, woman, girl, man, boy i dont want the array to print any string twice, i want the output to be like this: print all of them but print each once ---------- OUTPUT: girl, boy, man, woman

  • Below I have my 3 files. I am trying to make a dog array that aggerates...

    Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main {    public static void main(String[] args)    {    System.out.print("There are 5 humans.\n");    array();       }    public static String[] array()    {       //Let the user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT