vikas
java program to check whether a number is pallindrome or not using recursion???????
1 Answer(s)      4 years and 3 months ago
Posted in : Java Interview Questions

java program to check whether a number is pallindrome or not using recursion???????

Advertisement
View Answers

February 28, 2011 at 3:55 PM


Java check number is palindrome or not:

import java.util.Scanner;
public class NumberPalindrome
{

    public static boolean check(String s)
    {
        if(s.length() == 0 || s.length() == 1)
            return true;
        if(s.charAt(0) == s.charAt(s.length()-1))
            return check(s.substring(1, s.length()-1));
        return false;
    }

    public static void main(String[]args)
    {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter Number to check: ");
        int num=input.nextInt();
        String number = Integer.toString(num);
        if(check(number))
            System.out.println(number + " is a palindrome");
        else
            System.out.println(number + " is not a palindrome");
    }
}









Related Tutorials/Questions & Answers:
Advertisements