I am creating a program that counts the number of vowels, consonants, spaces, and punctuation in a string. Before moving on to anything else, I'm making sure that the vowel checker works. I've created a loop that seems to work logically, as I've run it through a java visualizer, and everything checks out. But, I get an error when I run it through the BlueJ IDE. It says: java.lang.StringIndexOutOfBoundsException: String index out of range. I have no idea what the issue is, and I would appreciate any and all help. This is a link to the java visualizer if anyone wants to test it for themselves, and I have the code posted below:
//**************************************************************
// Testing program for VCP program (temporary).
//
// @aaron_ford
// @version_1.0_11.9.17
//**************************************************************
public class VCPTest
{
public static void main(String[] args)
{
System.out.println("Enter a string.");
String user_str = "a vowel is here";
System.out.println("You entered: " + user_str);
char vowels[] = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
// counter variables
int v_counter = 0;
int c_counter = 0;
int s_counter = 0;
int p_counter = 0;
int count = 0;
int str_compare = user_str.charAt(count);
for (; count < str_compare; count++)
{
str_compare = user_str.charAt(count);
for (int a:vowels)
{
if (a == str_compare)
{
v_counter++;
}
}
}
System.out.println("There are " + v_counter + " vowels.");
System.out.println("There are " + c_counter + " consonants.");
System.out.println("There are " + s_counter + " spaces.");
System.out.println("There are " + p_counter + " punctuation marks.");
}
}