Gadgets 4 Students Career Guide Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
1.3k views
in JECRC University B.Tech(CSE-V Sem) Java Programming Lab by Goeduhub's Expert (5.8k points)
Java program to print the Armstrong numbers

1 Answer

0 like 0 dislike
by Goeduhub's Expert (5.8k points)
edited by
 
Best answer

Program Code

import java.util.*;

public class Armstrong

{

   public static void main(String[] args)

   {

   Scanner sc=new Scanner(System.in);

   System.out.print("Enter any number: ");

   int num=sc.nextInt();

   int sum=0,dig=0,rem,num1=num;

   int orgNum=num;

   while(num1!=0) //counting no of digits in number

   {

       num1/=10;

       dig++;

   }

   int flag=dig;

   for(int i=0;i<flag;i++)

   {

      rem=num%10;

      sum+=Math.pow(rem,dig);

      num=num/10;

   }

   if(orgNum==sum)

       System.out.println(orgNum+" is Armstrong number!");

   else

       System.out.println(orgNum+ " is not a Armstrong number!");

   }

}

Output

Enter any number: 407

407 is Armstrong number!


For more JU V Sem Java Lab Experiments Click here


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory
...