Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help figuring out how to add Finding the Vowels and Consonants of the user input. I am doing the program in DrJava if

I need help figuring out how to add Finding the Vowels and Consonants of the user input. I am doing the program in DrJava if that makes a difference. I've added a link with an image of the assignment here:

http://imgur.com/a/dUW23

Thanks!

import java.util.Scanner; import java.io.*; public class WordAnalyzerImproved{ public static void main (String [] args) throws IOException{ Scanner cin = new Scanner(System.in); System.out.println("Welcome to the Amazing Word Analyzer!: "); System.out.println("Enter a word"); String word = cin.next(); String word1 = cin.next(); String word2 = cin.next(); System.out.println("You entered: " + word); String str; int vowels = 0; int vowels1 = 0; int vowels2 = 0; char ch; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please enter your first word or END to end the program: "); //print out first letter of the word System.out.println("The first letter is: " + word.charAt(0) ); //print out the second letter of the word System.out.println("The second letter is: " + word.charAt(1) ); //print out the third letter of the word System.out.println("The third letter is: " + word.charAt(2) ); str = br.readLine(); for(int i = 0; i < str.length(); i ++) { ch = str.charAt(i);

if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U') vowels ++; } System.out.println("Vowels : " + vowels); System.out.println("Enter a word"); System.out.println("You entered: " + word1); System.out.println("Please enter your second word or END to end the program: "); //print out first letter of the word System.out.println("The first letter is: " + word1.charAt(0) ); //print out the second letter of the word System.out.println("The second letter is: " + word1.charAt(1) ); //print out the third letter of the word System.out.println("The third letter is: " + word1.charAt(2) ); str = br.readLine(); for(int i = 0; i < str.length(); i ++) { ch = str.charAt(i);

if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U') vowels ++; } System.out.println("Vowels : " + vowels1); /* System.out.println("Enter a word"); System.out.println("You entered: " + word2); System.out.println("Please enter your third word or END to end the program: "); //print out first letter of the word System.out.println("The first letter is: " + word2.charAt(0) ); //print out the second letter of the word System.out.println("The second letter is: " + word2.charAt(1) ); //print out the third letter of the word System.out.println("The third letter is: " + word2.charAt(2) ); //print out the fourth letter of the word System.out.println("The fourth letter is: " + word2.charAt(3) ); */ String words = cin.nextLine(); int count = 3; double sum = 3; double average = 3; cin = new Scanner (words); while (cin.hasNext()){ String userInput = cin.next(); double charNum = userInput.length(); sum = charNum + sum; count++; if (count > 3){ average = sum/ count; } } System.out.println("You entered three words with an average word length of = " +average); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago