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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!