It is a number that is equal to the sum of cubes of its digits. For example 153 
1^3+5^3+3^3=1+125+27=153.

For some basic concepts of java visit the link.

https://java4school.com/conditional-constructs-in-java

Write a program to accept a number and check whether it is an Armstrong number or not.

import java.io.*; 
public class ArmstrongNumber //number = the sum of the cubes of the digits e.g., 153 
{ 
public static void main() throws IOException 
{ 
   BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
   System.out.println("Enter a number"); 
   int num=Integer.parseInt(br.readLine()); 
   int n=num; 
   int sum=0; 
   while(num!=0) 
   { 
     int rem=num%10; 
     rem=(int)Math.pow(rem,3); 
     sum+=rem; 
     num=num/10; 
    } 
    if(sum==n) 
    { 
       System.out.println("Armstrong number"); 
    } 
   else 
    { 
      System.out.println("Not an Armstrong number"); 
    } 
  } 
} 

Output:
Enter a number
153
Armstrong number

Learn the basic concept of java https://youtu.be/TRm9r4gFTho

LEAVE A REPLY

Please enter your comment!
Please enter your name here