Skip to content

Commit 8a3e1e3

Browse files
authored
Create Armstrong_Number.java
Program to check whether the number is Armstrong number or not
1 parent ce7a3a3 commit 8a3e1e3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Armstrong_Number.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Java program to determine whether the number is Armstrong number or not
2+
3+
public class ArmstrongNumber {
4+
public static void main(String[] args)
5+
{
6+
7+
int n = 153;
8+
int temp = n;
9+
int p = 0;
10+
11+
while (n > 0) {
12+
13+
int rem = n % 10;
14+
p = (p) + (rem * rem * rem);
15+
n = n / 10;
16+
}
17+
18+
/* condition to check whether
19+
the value of P equals
20+
to user input or not. */
21+
if (temp == p) {
22+
System.out.println("Yes. It is Armstrong No.");
23+
}
24+
else {
25+
System.out.println(
26+
"No. It is not an Armstrong No.");
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)