Java program to check palindrome number using recursion

Simple Java program to check whether the number is palindrome or not by using Recursion.

Code:

import java.util.Scanner;

class xyz{

int pd(int i,int j,int[] a){

while(i<j){

if(a[i]==a[j]){i++;j--;pd(i,j,a);}

else{return 0;}

}

return 1;

}

}

class palindrome{

public static void main(String args[]){

int x,i=0;

System.out.println("Enter integer: ");

Scanner sc = new Scanner(System.in);

x=sc.nextInt();

int a[]=new int[10];

while(x!=0){

a[i]=x%10;

x=x/10;

i++;

}

xyz obj = new xyz();

if(obj.pd(0,i-1,a)==1){System.out.println("palindrome");}

else{System.out.println("Not Palindrome");}

}

}

Comments

Popular posts from this blog

C program to evaluate Prefix Expression using Stack data structure

Java Program to Implement sorting algorithm using TCP on Server application

C++ program to perform data transformation Min-max and Z score Normalization