-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathArmstrongNumberList.java
More file actions
43 lines (37 loc) · 851 Bytes
/
ArmstrongNumberList.java
File metadata and controls
43 lines (37 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.java.numbers;
/*
* Armstrong Number from 1 to 1000
*
* A positive number is called Armstrong number
* if it is equal to the
* sum of cubes of its digits
* for example 0, 1, 153, 370, 371, 407 etc.
*
* Armstrong Numbers are
* 1 153 370 371 407
*/
public class ArmstrongNumberList {
public static void main(String[] args) {
System.out.println("Armstrong Number from 1 to 1000 :: ");
for(int i=1; i<=1000; i++)
if(isArmstrongNumber(i))
System.out.print(i+" ");
}
private static boolean isArmstrongNumber(int num){
int digitsSum = 0;
int tempNum = num;
while( num > 0 ){
int digit = num % 10;
digitsSum += digit * digit * digit;
num = num / 10;
}
if(digitsSum == tempNum)
return true;
return false;
}
}
/*
OUTPUT
Armstrong Number from 1 to 1000 ::
1 153 370 371 407
*/