Question: Consider following method and answer the below questions: public boolean isP(String s) { if(s.length() == 1) return true; else if(s.length() == 2 && s.charAt(0) ==
Consider following method and answer the below questions:
public boolean isP(String s) {
if(s.length() == 1)
return true;
else if(s.length() == 2 && s.charAt(0) == s.charAt(1))
return true;
else if(s.charAt(0) == s.charAt(s.length() 1))
return isP(s.substring(1, s.length() - 1));
else
return false;
}
a) What does this method do?
b) Trace isP('hello')
c) Trace isP('mom')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
