I'm working in coding bat and one of the questions requires me to check if a certain char in a string is a certain letter. Then it returns an error:
Error: if (starttwochars.charAt(0) == "o")
Incompatible operand types char and String
Here is my code:
public String startOz(String str) {
String starttwochars = str.substring(0,1);
if (starttwochars.charAt(0) == "o"){
if (starttwochars.charAt(1) == "z") {
return "oz";
}
else {
return "o";
}
}
else {
if (starttwochars.charAt(1) == "z") {
return "z";
}
else {
return "";
}
}
}
Please tell me how I'm supposed to see if the certain char is the string. Thanks in advance