I am trying to make a method called Baller(String str, char chr)
which should return a boolean if the word contains the character. In the main method I have:
public static void main(String[] args) {
Balling ball= new Balling ();
System.out.println( ball.contains("Baller", 'a'));
System.out.println( ball.contains("Baller", 'A'));
}
What I did was this but it did not work:
public boolean contains(String str, char chr ) {
if(str.length() == chr) {
return true;
}
else {
return false;
}
}
What could be the problem?
ANSWER
public boolean contains(String str, char chr ) {
for(int i = 0; i < str.length(); i++)
if(str.charAt(i) == chr)
return true;
return false;
}
}