Gadgets 4 Students Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
1.2k 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

Where can I do online courses From Word's Top Instructors?

UDEMY::  Attend All Udemy Courses in Just INR 450[Coupon]
Coursera:: Join For FREE

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


3.3k questions

7.1k answers

395 comments

4.5k users

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
...