Hello, I posted the same question a little bit ago and it was answered correctly however I didn't ask it quite correctly so I wanted to post it again asking what I want correctly.
Basically the idea of the assignment the user should be able to enter a single word or sentence and it will output all the vowels in the sentence so for example the sentence "I think therefore I am" should print out {1,3,3,1,0} just once, then it should ask the user to input more words untill they type in STOP. Here is the code I believe it's very close to the solution I just don't know quite how to make it work. Again sorry to post the same question again, it's due soon and I am unsure.
public static void main(String args[]){
Scanner keyboard= new Scanner(System.in);
System.out.println("Enter string ");
String input = keyboard.nextLine();
while (!"STOP".equals(input)){
int[] vowels = vowelCount(input);
input = keyboard.next();
System.out.print("{");
for(int i=0; i<5; i ++) {
System.out.print(vowels[i] + " ");
}
System.out.print("}");
System.out.println();
System.out.println("Enter string ");
}
}
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;
}
}
import java.util.Scanner;
public class CountVowels {
public static void main(String[]args)
{
String userIn = "";
int vowels[] = new int[5];
Scanner keyboard = new Scanner(System.in);
do
{
System.out.print("Enter a sentence: ");
userIn = keyboard.nextLine().trim();
vowels = vowelCount(userIn);
if(userIn.equalsIgnoreCase("Stop"))
{
System.out.println("Goodbye!");
System.exit(0);
}
System.out.print("\nVowel count: { ");
for(int i = 0; i < 5; i++)
{
if(i == 4)
System.out.println(vowels[i] + " }");
else
System.out.print(vowels[i] + ", ");
}
System.out.println();
}while(!userIn.equalsIgnoreCase("Stop"));
}
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;
}
}
********************************************************************* SCREENSHOT ******************************************************

Hello, I posted the same question a little bit ago and it was answered correctly however...
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...
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 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....
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.
Question 39 (1 point) Which one of the following statements can be used to get the fifth character from a string str? char c - str.charAt(4): char c - str[5]: char c = str(4): char c - str.charAt(5): Question 40 (1 point) What does the following statement sequence print If the user input is 1234 public static void main(String args) Scanner in new Scanner (System.in); System.out.print("Enter a number: "); String strin.next( St 456; System.out.println(str) Compile-time error 123456 579 Run-time error
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...
Java debugging in eclipse
package edu.ilstu;
import java.util.Scanner;
/**
* The following class has four independent debugging
* problems. Solve one at a time, uncommenting the next
* one only after the previous problem is working correctly.
*/
public class FindTheErrors {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
/*
* Problem 1 Debugging
*
* This problem is to read in your first name,
* last name, and current year and display them in
*...
I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...
Write a java programm that calculates the total of a retail sale should ask the user for the following: The retail price of the item being purchased The sales tax rate Once these items have been entered, the program should calculate and display the following: The sales tax for the purchase The total of the sale I tried doing it here. but it is not giving me the right answer. kindly help correct the errors. import java.util.Scanner; public class SalesTax...
I am gettting error saying that I need to initialize variable but I want to get inputs from the user and want to print them out. (using "for" loop) public static void main(String[] args) { String input; int i; Scanner sc = new Scanner(System.in); for (i=1; i < 5; i++) { System.out.print(i+ ". Please enter a name: "); input = sc.nextLine(); } System.out.println("All names are here:" + input); } }