File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+ import java .lang .Math ;
3+ public class Armstrong
4+ {
5+ static boolean isArmstrong (int n )
6+ {
7+ int temp , digits =0 , last =0 , sum =0 ;
8+ temp =n ;
9+
10+ while (temp >0 )
11+ {
12+ temp = temp /10 ;
13+ digits ++;
14+ }
15+
16+ temp = n ;
17+
18+ while (temp >0 )
19+ {
20+ last = temp % 10 ;
21+ sum += (Math .pow (last , digits ));
22+ temp = temp /10 ;
23+ }
24+
25+ if (n ==sum )
26+
27+ return true ;
28+
29+ else return false ;
30+ }
31+
32+ public static void main (String args [])
33+ {
34+ int num ;
35+ Scanner sc = new Scanner (System .in );
36+ System .out .print ("Enter the max: " );
37+
38+ num =sc .nextInt ();
39+ System .out .println ("Armstrong Number up to " + num + " are: " );
40+ sc .close ();
41+
42+ for (int i =0 ; i <=num ; i ++)
43+ if (isArmstrong (i ))
44+ System .out .print (i + ", " );
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments