Palindrome Program in Java using While Loop


Palindrome is nothing but any number or a string which remains unchanged when it is reversed. For example: 121 or RAR. It is observable that letters form reflect images on turn around.

public class PalindromeProgramInJavaUsingWhileLoop {
public static void main(String[] args) {
       int rem, rev= 0, temp;
       int n=121; // Input Number
       temp  = n;
       while( n != 0 ){
            rem= n % 10;
            rev= rev * 10 + rem;
            n=n/10;
       }
       if (temp == rev){
          System.out.println(temp + " is a palindrome.");
       }else{
          System.out.println(temp + " is not a palindrome.");
       }
    }
}

Output: 121 is a palindrome number

Learn More about Palindrome:


%d bloggers like this: