4544 Shares

Java Program about Vowels just need minor help?

Java Program about Vowels just need minor help? Topic: Tolowercase string
July 21, 2019 / By Driskoll
Question: I got the program down, but I need to move the while Statement, I took the Break (Plus I was also informed to take it out) out because I want Repetition, for the "put in another string" response but at the same time if they press 'e' it will automatically end the program. I'm almost done I just need to know where to put the stuff in the right order? Also the comment on the bottom is the comand I need to tell the program to stop if somebody just keys in e and e alone, I just don't know where to put it without errors. Thx import java.util.Scanner; public class VowelsandCons { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(" Please input a string: "); String str = input.nextLine(); countVowelConsCount(str); } public static void countVowelConsCount(String s) { String vowels = "aeiou"; int vowelCount=0; int consCount=0; while( true ) { char str[] = s.toLowerCase().toCharArray(); for(char c1:str){ if(vowels.indexOf(c1)!=-1) { vowelCount++; } else{ consCount++; } } System.out.println("Total Amount of Vowels: "+vowelCount); System.out.println("Total Amount of Consonants: "+consCount); System.out.println("Please input a String"); // if ( input.nextLine().equalsIgnoreCase('e')) } } }
Best Answer

Best Answers: Java Program about Vowels just need minor help?

Briscoe Briscoe | 3 days ago
I just rearranged the while loop Here's the modified code: public class CountVowelsAndConsonents { public static void main(String[] args) { while(true){ Scanner input = new Scanner(System.in); System.out.print(" Please input a string: "); String str = input.nextLine(); if(str.equals("e")) break; else countVowelConsCount(str); } } public static void countVowelConsCount(String s){ String vowels = "aeiou"; int vowelCount=0; int consCount=0; char str[] = s.toLowerCase().toCharArray(); for(char c1:str){ if(vowels.indexOf(c1)!=-1) { vowelCount++; } else{ consCount++; } } System.out.println("Total Amount of Vowels: "+vowelCount); System.out.println("Total Amount of Consonants: "+consCount); } }
👍 234 | 👎 3
Did you like the answer? Java Program about Vowels just need minor help? Share with your friends

We found more questions related to the topic: Tolowercase string


Briscoe Originally Answered: Java Program about Vowels just need minor help?
I just rearranged the while loop Here's the modified code: public class CountVowelsAndConsonents { public static void main(String[] args) { while(true){ Scanner input = new Scanner(System.in); System.out.print(" Please input a string: "); String str = input.nextLine(); if(str.equals("e")) break; else countVowelConsCount(str); } } public static void countVowelConsCount(String s){ String vowels = "aeiou"; int vowelCount=0; int consCount=0; char str[] = s.toLowerCase().toCharArray(); for(char c1:str){ if(vowels.indexOf(c1)!=-1) { vowelCount++; } else{ consCount++; } } System.out.println("Total Amount of Vowels: "+vowelCount); System.out.println("Total Amount of Consonants: "+consCount); } }
Briscoe Originally Answered: Java Program about Vowels just need minor help?
i don't think of it concerns in java yet you will possibly often want a tail-recursive function (merely nutrients for theory): function countVowels(String s, int numVowels)   IF length(s) == 0     return numVowels   ELSE     IF first char is vowel       countVowels(relax(s), numVowels + a million)     ELSE       countVowels(relax(s), numVowels) In my pseudocode, "relax()" returns each and every thing after the 1st character interior the string (in Java it quite is something like substring(a million,s.length())). the belief is that once the recursive call to countVowels returns we don't could do any further artwork. a smart compiler can convert this into very useful merchandise code.

Aiah Aiah
i don't think of it concerns in java yet you will possibly often want a tail-recursive function (merely nutrients for theory): function countVowels(String s, int numVowels)   IF length(s) == 0     return numVowels   ELSE     IF first char is vowel       countVowels(relax(s), numVowels + a million)     ELSE       countVowels(relax(s), numVowels) In my pseudocode, "relax()" returns each and every thing after the 1st character interior the string (in Java it quite is something like substring(a million,s.length())). the belief is that once the recursive call to countVowels returns we don't could do any further artwork. a smart compiler can convert this into very useful merchandise code.
👍 100 | 👎 0

Aiah Originally Answered: Can someone help me get started on this Java program?
EDIT: http://pastebin.com/f13483554 ======================================... Here's the code. import java.io.*; public class OddEven { public static void main(String args[])throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int n,i,oddSum=0,evenSum=0; char a='\b'; System.out.println("Enter the number: "); n=Integer.parseInt(in.readLine()); for(i=1;i<=n;i++){ if(i%2==0){ evenSum+=i; } else{ oddSum+=i; } } System.out.print("Sum of even integers = "); for(i=1;i<=n;i++){ if(i%2==0) System.out.print(i+" + "); } System.out.print(a); System.out.print(a); System.out.print("="+evenSum); System.out.println(); System.out.print("Sum of odd integers = "); for(i=1;i<=n;i++){ if(i%2!=0) System.out.print(i+" + "); } System.out.print(a); System.out.print(a); System.out.print("="+oddSum); } } Here's the code, in case some part of the code gets truncated on Yahoo Answers.http://pastebin.com/f78e46c5a Hope this helps. Let me know if you have any queries. Have fun :)
Aiah Originally Answered: Can someone help me get started on this Java program?
int evens = 0; int odds = 0; int input = 15; for ( int i = 1; i <= input; i++ ) { ..... if ( i % 2 == 0 ) { .......... evens++; ..... } else { .......... odds++; ..... } } System.out.println( "Evens: " + evens + ", Odds: " + odds );

If you have your own answer to the question tolowercase string, then you can write your own version, using the form below for an extended answer.