Maintenance - We're currently working on things and you might experience some issues. Should be wrapped up soon!

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
Having trouble writing a java method.
Post Body

Hi everyone!!! I'm a super beginner taking some classes at a local community college. We're on writing methods right now, and I'm running into a roadblock. I have the code below written so far for the method I'd like to use (i can post the full file code if you'd like).

int vowels;
char ch;    
for(int i = 0; i < input.length() ; i  ){
    vowels = 0;


           //as i   increases, so does the position being tested.
            ch = input.charAt(i);
            if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch == 'o'
                   || ch == 'O' || ch == 'u' || ch == 'U' || ch == 'y' || ch == 'Y'){
               vowels  ; //increases vowels variable, such that it only will increase if the 
                         //string has characters matching one of those characters

            }
       }
return vowels;
}

Currently, the "return vowels;" portion of the code (on line 16) is giving an error, and I'm stumped as to why.

EDIT: Full code is posted in comments in response to /u/Nincodedo

EDIT 2: It has been solved!! I needed to initialize vowels outside the loop instead of inside in this case. Thanks again to /u/Nincodedo.

Author
Account Strength
100%
Account Age
11 years
Verified Email
Yes
Verified Flair
No
Total Karma
31,619
Link Karma
10,943
Comment Karma
20,450
Profile updated: 20 hours ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
7 years ago