Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


DEVABRAT ACHARYA
palindrom
2 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


write a program to accept a no. and find that no. is a palindrom or not using function.


Advertisement
View Answers

November 11, 2010 at 7:11 AM


static class Palindrome

{

int n;

Palindrome()

{

n=121;

}

Palindrome(int x)

{

n=x;

}

void checkPallin()

{

int a;

a=n;

int s=0,r;

while(n!=0)

{

r=n%10;

s=s*10+r;

n=n/10;

}

if(a==s)

System.out.println("Given Number is Palindrome");

else

System.out.println("Given Number is not Palindrome")

}

}

public static void main(String[] args)

{ int x = Integer.parseInt(s[0]); Palindrome p1=new Palindrome();

p1.checkPallin();

Palindrome p2=new Palindrome(x);

p2.checkPallin();

}

}



November 12, 2010 at 4:58 PM


Hi Friend,

You can try the following code:

 import java.util.*;

    public class CheckPalindomeNumber {
         public static void main(String [] args){
      Scanner input=new Scanner(System.in);
      System.out.println("Enter number");
      int num= input.nextInt();
        int n = num;
        int rev=0;
        for (int i=0; i<=num; i++){
          int r=num%10;
          num=num/10;
          rev=rev*10+r;
          i=0;
        }
        if(n == rev){
        System.out.print("Number is palindrome!");
        }
        else{
        System.out.println("Number is not palindrome!");
        }
      }
         }

Thanks



Related Tutorials/Questions & Answers:
palindrom
palindrom  write a program to accept a no. and find that no. is a palindrom or not using function
string palindrom using vbscript?
string palindrom using vbscript?  string palindrom using vbscript
Advertisements
Advertisements
 

 

 

DMCA.com