Write a Java Program to Check Whether a Number is Palindrome or Not using Do-While Loop
import java.util.Scanner; public class PalindromeDoWhile { 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; do { reminder=n%10; reverse=reverse*10+reminder; n=n/10; }while(n!=0); 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: 99999 99999 is a pallindrome
No comments:
Post a Comment
If you have any doubts, please let me know