I am trying to run the following code:
import textio.TextIO;
public class Main{
public static void main(String[] args){
String str; // Line of text entered by the user.
System.out.println("Please type in a line of text.");
str = TextIO.getln();
int vcount;
int ccount;
char y[] = str.toCharArray();
int size = y.length;
int i = 0;
while(i != size)
{
if(y[i]>='A' && y[i]<='Z')
{
if(y[i]=='A'||y[i]=='E'||y[i]=='I'||y[i]=='O'||y[i]=='U')
{
++vcount;
}
else
{
++ccount;
}
++i;
}
int ratio = vcount/ccount;
System.out.println("The vowel/consonant ratio of arithmetic is" + ratio);
}
}
}
This code is not compiling because the compiler says the variables vcount
and ccount
are not initialized. I think I have already initialized both these variables at the beginning of the code. Where am I going wrong?