private boolean isVowel(char c)
{
String vowel = "aiueo";
boolean isVow = false;
if (vowel.indexOf(c) != -1)
isVow = true;
return isVow;
}
public String getPigLatinVersion()
{
String x = "";
while (input.hasNext())
{
String word = input.next();
if (word.isVowel(word.charAt(0)) == false)
{
String y = "";
y = word + "ay";
}
The thing is that it generates a compiler error
C:\Documents and Settings\Aditya Aditama H\My Documents\CSC\test\WordProcessor.java:16... cannot find symbol
symbol : method isVowel(char)
location: class java.lang.String
if (word.isVowel(word.charAt(0)) == false)
why is that??? help
Private method inside a method! (java expertts help)?
The reason is that isVowel() is not a method of String. That's why the compiler complains when you say word.isVowel(). Try simply isVowel(word.charAt....), and you'll be in better shape.
Reply:arbeit is correct. Since the isVowel() method is a member of your class (not of class String), you can use it elsewhere in your class directly without specifying an object to refer to.
...
if (isVowel(word.charAt(0)) == false)
...
pear
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment