Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

need help immediately with this code

807599Mar 18 2007 — edited Mar 18 2007
hi, every i' m very new to here and I 'm very new to java
i'm trying to do the volwel and consonants assignment
i don't know what is worng with my code
because it did not display the correct answer
so please anybody help
thank in advance


import java.util.Scanner;
public class VoCo
{
public static void main(String[] args)
{
String str;
int consonants =0;
int vowels=0;
int letter =0;
String Vol = "aeiou";
Scanner keyboard = new Scanner(System.in);


System.out.println("Enter a string word: ");
str = keyboard.nextLine();
char[] array;
array=str.toCharArray();
for(int i=0; i< array.length; i++)

{
if(Character.isLetter(Vol.charAt(i)))
{
letter++;

if(Vol.indexOf(Vol.charAt(i))>=0)
{
vowels++;
}
else
consonants++;
}
}

System.out.println(" There are " + letter + " letter" );
System.out.println(" There are " + vowels + " vowels" );
System.out.println(" There are " + consonants + "consonants" );

}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 15 2007
Added on Mar 18 2007
6 comments
107 views