Skip to content

Commit 4b7c856

Browse files
ArmStrong Number and Factors Number program
ArmStrong Number and Factors Number program Co-Authored-By: Manish Upadhyay <ermanishupadhyay@gmail.com>
1 parent 26e2291 commit 4b7c856

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/JavaPrograms/ArmStrongNumber.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package JavaPrograms;
2+
3+
public class ArmStrongNumber {
4+
5+
public static void main(String[] args) {
6+
// Armstrong number --> 153 ----> 1*1*1 + 5*5*5 + 3*3*3 = 153
7+
8+
int num = 371;
9+
int actualNum = num;
10+
double result = 0;
11+
12+
while(actualNum != 0) {
13+
int n = actualNum % 10;
14+
result = result + Math.pow(n, 3);
15+
actualNum = actualNum / 10;
16+
}
17+
if(result == num) {
18+
System.out.println(num + " is an armstrong number");
19+
}
20+
else {
21+
System.out.println(num + " is not an armstrong number");
22+
}
23+
24+
}
25+
26+
}

src/JavaPrograms/FactorsNumber.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package JavaPrograms;
2+
3+
public class FactorsNumber {
4+
5+
public static void main(String[] args) {
6+
// Factors Number : --> 10 : 1,2,5,10
7+
// 60 --> 1,2,3,4,5,6,10,12,15,20,30,60
8+
9+
int num = 35;
10+
for(int i=1; i<=num; i++) {
11+
if(num % i == 0) {
12+
System.out.println(i + " ");
13+
}
14+
}
15+
16+
}
17+
18+
}

0 commit comments

Comments
 (0)