Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Program {
- public static boolean isPalindrome(String str) {
- char[] chars = str.toCharArray();
- int start = 0;
- int end = chars.length - 1;
- while(start < end) {
- if(chars[start] != chars[end])
- return false;
- ++start;
- --end;
- }
- return true;
- }
- public static void main(String[] args) {
- System.out.println(isPalindrome("foobar"));
- System.out.println(isPalindrome("foof"));
- System.out.println(isPalindrome("abc 121 cba"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement