Home Answers Viewqa Java-Interview-Questions java program to check whether a number is pallindrome or not using recursion???????

 
 


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

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

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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.