Wednesday, 2 December 2020

Palindrome using While Loop

Write a Java Program to Check Whether a Number is Palindrome or Not using While Loop  
import java.util.Scanner;
public class palindromeWhile 
{
	public static void main(String[] args) 
	{
		int reminder,reverse=0,temp;
		Scanner scan = new Scanner(System.in);
		System.out.println("\nEnter a Number: ");
		int n = scan.nextInt();
		temp=n;
			while(n>0)
			{
				reminder=n%10;
				reverse=reverse*10+reminder;
				n=n/10;
			}
		if(temp==reverse)
		{
			System.out.println("\n\n"+temp+" is a pallindrome");
		}
		else
		{
			System.out.println("\n\n"+temp+" is not a pallindrome");
		}
	}
}


Output
Enter a Number: 
456321

456321 is not a pallindrome


No comments:

Post a Comment

If you have any doubts, please let me know

Pattern 31 & 32