Computer Science, asked by aashihunjan5, 8 months ago

write a programme in java to input any no. and check whether a no. is palendrome or not by using a while loop​

Answers

Answered by keyboardavro
0

Answer:

Explanation:

class PalindromeExample{  

public static void main(String args[]){  

 int r,sum=0,temp;    

 int n=454;//It is the number variable to be checked for palindrome  

 

 temp=n;    

 while(n>0){    

  r=n%10;  //getting remainder  

  sum=(sum*10)+r;    

  n=n/10;    

 }    

 if(temp==sum)    

  System.out.println("palindrome number ");    

 else    

  System.out.println("not palindrome");    

}  

}  

Answered by anindyaadhikari13
1

Question:-

Write a program in Java to input a number and check whether it is Palindrome or not using while loop.

Program:-

import java.util.*;

class Palindrome

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int a, b, s=0;

System.out.print("Enter a number: ");

a=sc.nextInt();

b=a;

while(b!=0)

{

s=s*10+b%10;

b/=10;

}

if(s==a)

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

else

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

}

}

Similar questions