Trimorphic Number in java

Checking Trimorphic Number


What is Trimorphic Number ?
> A Trimorphic Number is a number which cube's last digit is the number it self . ex- 4 is trimorphic number because, 4 cube is 64 and the last digit of 64 is 4 the 4 itself so that's why 4 is a trimorphic number. 

Steps to do this:-
1. take 4 integers c,n,r,t (  n is for user input number a is for to store the cube of the number r is for to store the remainder of the cube and t is for to store the user input value )

2. take a scanner class and make an object and take a number from user and scan it

3.store the number in t
t=n;

4. calculate the cube of the number and store it in a
a=n*n*n;

5.now find the last number of the cube and to do this we have to do
r=a%10 ;
when we do module of a number by 10 it will store the last number

6.now check this
if(t==r)
{
print " trimorphic number ";
}
else
{
print " not trimorrphic number "
}

7.save and run

The Source Code
 import java.util.Scanner;
 class trimorphicnumber
 {
     public static void main(String[] args) {
         Scanner s=new Scanner(System.in);
         int a,n,r;
         System.out.println("enter the number");
         n=s.nextInt();
         a=n*n*n;
         r=a%10;
         int t=n;
         if (t==r)
         {
             System.out.println("the cube is :"+a);
             System.out.println("this is trimorphic number");
         }
         else {
             System.out.println("the cube is :"+a);
             System.out.println("this is not a trimorphic number");
         }
     }
}

OUTPUT



Watch My Video

Comments

Popular Posts