I'm fairly new to java, so forgive my incompetence. This program is pretty simple, I'm trying to take the string that a user inputs and return the vowels in the string. The error I'm getting is as follows:

> VowelsA3.java:16: error: cannot find symbol
>            if (isVowel(letter) == true)
>                ^
>   symbol:   method isVowel(char)
>   location: class VowelsA3
> 1 error

Here's my code for "VowelsA3" (my main that will not compile):

import java.util.Scanner;

public class VowelsA3 
      public static void main (String[] args) 
      Scanner scan = new Scanner(System.in);

      System.out.println("Please enter a string.");
      String userInput = scan.nextLine();
      char letter = 'x';

      for (int i = 0; i <= userInput.length(); i++) 
           letter = userInput.charAt(i);
           if (isVowel(letter) == true)

And my method "isVowel" that does compile:

public class isVowel 
    public static boolean isValidVowel(char letter)
      boolean trueVowel = false;
      if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u')
          trueVowel = true;
          trueVowel = false;  
      return trueVowel;

Any ideas? This is my first time creating and working with methods so I'm sure it's something stupid. Sorry if it's a waste of anyone's time.

Recommended Answers

All 9 Replies

Oh dear, I'm almost as embarassed pointing this out as you will be...
Your method is called isValidVowel, but you try to call a method called isVowel.

I changed it to

if (isValidVowel(letter) == true)

and the same error is still popping up.

You defined the static method in a different class, so you need to specify that class when you call the method, ie

Also, it's utterly pointless to add ==true to a boolean expression - all it does is convert true to true and false to false !

Hi James, sorry to bother you but changing the line to:

 if (isVowel.isVowelValid(letter) = true)

Still gives me the error:

VowelsA3.java:13: error: cannot find symbol
           if (isVowel.isVowelValid(letter) = true)
  symbol:   method isVowelValid(char)
  location: class isVowel
1 error

I just can't seem to get VowelA3 to compile at all. Any other ideas?

you've done it right this time but you've assigned "true" to "isVowel.isVowelValid(letter)" rather than compare. Use "==" not "="

How can I make this clearer?
Testing a boolen expression to see if it's true by using == true is stupid.
A boolean expression (like your isValidVowel method call) is already either true or false.
(true == true) is true
(false == true) is false
the == true does NOTHING except show that the programer doesn't understand booleans.

Way to be rude, I've already said I'm new to Java so I'm really not sure why you have to be suddenly abrasive over the whole thing.

One of you is telling me to use "==" and the other is telling me that "=" or "==" is dumb - neither work, so I'm totally lost. Perhaps it was wrong of me to think people here had patience with people new to Java. I'll take my question elsewhere.

Please don't be offended - it's nothing personal. People here are more inclined to be forthright than polite for polite' sake. It's the information content that counts. :)

Using = true is wrong. That tries to assign the value true, not test for it. To test for it you need ==

But what I'm telling you is that you don't need the == true at all. It's a common beginner mistake to think every if test needs a logical operator (==, > etc). All it needs is a boolean expression, for instance a call to a method (like yours) that returns a boolean. Using the redundant == is a sign that the programmer didn't really understand boolean expressions - but that's usually just inexperience, not a character defect!

Bottom line: you just code

 if (if (isVowel.isVowelValid(letter)) ...

your method returns a boolean, and that's all you need for an if test.

If u use an boolean expresion in an condition. You need eval this answer. Example:

//results if x is less than 4 is TRUE 
//results if is FALSE 

.... here is the opposite, check the simbol ! (Used for negation)

//results if x IS NOT less than 4 is true 

... Then if u use an method that evaluate it and return an boolen value u need only evaluate this result. Example:

boolean exists = true; 
//all operations here when exists be true 

And if u need an opposite value use this.

//all operations here when exists be false 

... So in ur example, only need use

//all operations when isVowelValid return true 

Is all. Please, take a moment and read all answers :).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.