Showing posts with label Java program to check. Show all posts
Showing posts with label Java program to check. Show all posts

Java Program to Check the Armstrong numbers | JAVA POINT Numbers

Java Program to Check the Armstrong numbers 



Armstrong number in Java
Armstrong number



Armstrong number

A number will be called Armstrong if the sum of cubes of each digits is equal to the original number.


Program


import java.util.Scanner;

public class Armstrong

{

    public static void main(String args[])

    {

        Scanner ob=new Scanner(System.in);

        System.out.println("Enter the number to be checked.");

        int num=ob.nextInt();

        int a,i,sum=0;

        i=num;


        while(num!=0) 

        {

            a=num%10;

            sum=sum+a*a*a;

            num=num/10;

          }

          if(sum==i)

              System.out.println(i+" is an Armstrong Number.");

          else

              System.out.println(i+" is not a Armstrong Number.");

    }

}


/*

Output :


Enter the number to be checked : 153

153 is an Armstrong Number.

(Workings 153 = 1*1*1 + 5*5*5 + 3*3*3)

*/


Also read :


Java program to check the Neon Number | JAVA POINT

 

Write a Java program to check that a given number is Neon number or not.


Neon number Java program



Neon number

A number is said to be a Neon Number if the sum of digits of the square of the number is equal to the number itself.


PROGRAM :


import java.util.*;

public class neon

{

    public static void main(String args[])

    {

        Scanner ob=new Scanner(System.in);

        System.out.print("\nEnter the number to be checked : ");

        int num=ob.nextInt();

        int square=num*num;

        int sum=0;

        while(square!=0)//Loop to find the sum of digits.

        {

            int a=square%10;

            sum=sum+a;

            square=square/10;

        }

        if(sum==num)

        {

            System.out.println(num+" is a Neon Number.");

        }

        else

        {

            System.out.println(num+" is not a Neon Number.");

        }

    }

}

/*

Output :


Enter the number to be checked : 9

 9 is a Neon Number.

(Workings 9*9=81 sum of digits of square = 8 + 1 = 9.)

*/



Java program to check the DISARIUM number | JAVA POINT

 

Write a Java program to check that a given number is  DISARIUM number or not.



DISARIUM number



DISARIUM number

A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number.


PROGRAM :


import java.util.Scanner;

class disarium

  public static void main(String[] args)

  {

   Scanner sc=new Scanner(System.in);

   System.out.print("\nEnter the number to be checked : ");

   int n=sc.nextInt();


   int copy = n, d = 0, sum = 0;

   String s = Integer.toString(n); //converting the number into a String

   int len = s.length(); //finding the length of the number i.e. no.of digits

       

   while(copy>0)

   {

    d = copy % 10; //extracting the last digit

    sum = sum + (int)Math.pow(d,len);

    len--;

    copy = copy / 10;

   }

             

   if(sum == n)

     System.out.println(n+" is a Disarium Number.");

   else

     System.out.println(n+" is not a Disarium Number.");

  }

}



/*

Output :


Enter the number to be checked : 135

135 is a Disarium Number.

(Workings 1+3*3+5*5*5 = 1+9+125 = 135

other DISARIUM are 89, 175, 518 etc)

*/