Write a recursive Java method that takes a String as a parameter and returns true if the String is a palindrome. You may assume that the string only contains lower case characters (i.e. no numbers, spaces, punctuation, etc).

What will be an ideal response?

```
public boolean isPalindrome(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 isPalindrome(s.substring(1, s.length() - 1));
else
return false;

}
```

Computer Science & Information Technology

You might also like to view...

A cell ________ color is also known as the background color

A) fill B) style C) grid D) shading

Computer Science & Information Technology

A linked list class uses a Node class with successor reference next and field element to store values. It uses a reference first to point to the first node of the list. Code to print all elements stored in the list can be written as

``` A) System.out.print(first); B) Node p = first; while (p != null) { System.out.println(p.element); p = p.next; } C) Node p = first; while (p != null) System.out.println(p.next); D) Node p = first; for (p!= null) { System.out.println(p.element); p++; } ```

Computer Science & Information Technology