Domanda di colloquio di ServiceNow

Write a program to find whether a given string is palindrome or not?

Risposta di colloquio

Anonimo

18 dic 2015

You just have to create new String variable where you add the characters from right to left (reverse order) one by one and compare it to the original String. If they are both the same, then return true. This is the Java implementation: public static boolean palindrome(String a){ String reverse =""; for(int i = a.length(); i > 0; i--){ reverse = reverse + a.substring(i-1,i); } if(reverse.equals(a)) return true; return false; }