SuperPalindrome Number in JAVA

Super Palindrome Number

Super Palindrome Number: A Super Palindrome Number is a Palindrome Number whose square is also Palindrome.

Example:

Input         : 11
Square      : 11 X 11 = 121
Output     : It is a Super Palindrome Number

Input         : 22
Square      : 22 X 22 = 484
Output     : It is a Super Palindrome Number

Input         : 44
Square      : 44 X 44 = 1936
Output     : It is not a Super Palindrome Number
 

Algorithm and Program given below :-

Algorithm :-

1. Get the number to check for palindrome.

2.   Hold the number in another variable
3.   Calculate and store the square of the number
4.   Check if the number is palindrome or not
5.   If it is not palindrome print “It is not a Palindrome Number”
6.   Else Check if the square is palindrome or not.
7.   If the square is palindrome print “It is a SuperPalindrome Number”
8.   Otherwise print “It is not a SuperPalindrome Number”.
9.   Compile and Run the Program.
 

Program :- 

import java.io.*;
import java.util.*;
class SuperPalindrome
{
    public static void main(String args[])
    {
        Scanner in= new Scanner(System.in);
        int n,p,sq,x,rev,s=0,res,sum=0;
        System.out.println("Enter No.");
        n= in.nextInt(); // Input number from user
        p=n; // store the entered number in "p" variable
        sq= n*n;
        x=sq;
        while(n>0)
        {
            rev=n%10; // extract last digit of the number
            s=s*10+rev; // store the digit last digit
            n=n/10; // extract all digit except the last
        }
        if(p==s) // Checking if the number is Palindrome or not
        {
            while(sq>0)
            {
                res=sq%10;
                sum=sum*10+res;
                sq=sq/10;
            }
            if(sum==x)
            {
                System.out.println("It is a SuperPalindrome Number : "+p);
            }
            else
            {
                System.out.println("It is not a SuperPalindrome Number : "+p);
            }
        }
        else
        {
            System.out.println("Number is not Palindrome : "+p);
        }
    } // end of main method
} // end of class


Video Link of this Program : https://youtu.be/peP-aFGn4YQ
Follow me on Instagram

All the Best :)
Keep Learning :) 

Comments

Popular posts from this blog

Frequency of each digit of a number in Java

Trimorphic Number in JAVA

Tri-Automorphic Number in JAVA