For a question i'm supposed to get the user to enter a string then count the number of consonants, vowels, numbers and "other" characters in the string.
So first we would get the length of the string. I know how to do that.
Next I made variables for consonants, vowels and numbers and set them all equal to 0. Then I set a variable called "index" equal to 0. My plan is to make a loop that will go over every single character in the string and if it is a vowel, vowel++, if it is a number, number++ and so forth. After checking an index I will index++. Once the first index of the string is looked over, the next index is looked over assuming the index is less than or equal to the length of the string.
My problem is I don't know how to access an index. I was thinking
char c = characters.charAt(index);
and then another nested loop where if c is a vowel, etc. it will be added to the vowel counter or the appropriate counter. So after this loop plays the first time for example, index will be set to 1 from 0 and then the 2nd character will be checked. This goes on until all of the characters in the string are looked at.
But how do I do this? How do I access a certain index?
I have some code done but I don't want to post it because it is for a school assignment.
So first we would get the length of the string. I know how to do that.
Next I made variables for consonants, vowels and numbers and set them all equal to 0. Then I set a variable called "index" equal to 0. My plan is to make a loop that will go over every single character in the string and if it is a vowel, vowel++, if it is a number, number++ and so forth. After checking an index I will index++. Once the first index of the string is looked over, the next index is looked over assuming the index is less than or equal to the length of the string.
My problem is I don't know how to access an index. I was thinking
char c = characters.charAt(index);
and then another nested loop where if c is a vowel, etc. it will be added to the vowel counter or the appropriate counter. So after this loop plays the first time for example, index will be set to 1 from 0 and then the 2nd character will be checked. This goes on until all of the characters in the string are looked at.
But how do I do this? How do I access a certain index?
I have some code done but I don't want to post it because it is for a school assignment.


