vowels = wordcount.vowelNum(); //counts the vowels
consonants = wordcount.consNum(); //counts the consonants, this is not working properly.

the consNum() method:

int length = word.length();

		for(int i = 0; i < length; i++){
			if(word.charAt(i) == 'a' || word.charAt(i) == 'u'|| word.charAt(i) == 'i'|| word.charAt(i) == 'e'|| word.charAt(i) == 'o'){
	consCount = (word.length() - vowelCount);
	return consCount;

the above method is giving me weird results, for example if i typed in "dexter" and it would say it has 2 consonants. the vowel count method, however, works.

Edited by plasticfood: n/a

7 Years
Discussion Span
Last Post by plasticfood

Where are you initializing vowelCount? Anyway, you could just reuse the vowelNum method and do something like this: return word.length() - vowelNum();


are you trying to have the same method counting both consonants and vowels? this method you provided does not return the number of vowels. it does count the number of vowels, but it does not return it.


ok nevermind i fixed it by editing the consNum() method to accept an argument which is the number of vowels (provided from the vowelsNum() method), and it works that way.

but i still don't understand why the original method didn't work. the consNums() method only returns the number of consonants and NOT the number of vowels (that's the vowelsNum method's job). i intended for it to just calculated the # of vowels, so it can figure out the # of consonants.

and death oclock, your method works too, thanks.

Edited by plasticfood: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.