Skip to content

Commit 9bc05e9

Browse files
committed
feat: Check if a number is an Armstrong number (3-digit)
🧠 Logic: - Take integer input `n`, store original in `m`. - Initialize `sum = 0`. - Extract digits using `% 10` and compute cube of each digit. - Accumulate sum of cubes. - After loop, compare `sum` with original number `m`. - If equal → Armstrong number. Signed-off-by: Somesh diwan <[email protected]>
1 parent d6f147b commit 9bc05e9

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Section8LoopAB/src/ArmsStrongNumber.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/*
22
Find a number is armstrong number or not.
3-
A number is armsstrong, sum of the cubs of digits of number, n =153,
4-
3 cube + 5 cube + 1 cube + 153 then its Armsstrong number.
3+
A number is arms strong, sum of the cubs of digits of number, n =153,
4+
3 cubes + 5 cubes + 1 cube = 153 then its Armstrong number.
55
*/
66

77
import java.util.Scanner;
88

99
public class ArmsStrongNumber {
10-
public static void main(String[] args)
11-
{
10+
public static void main(String[] args) {
1211
Scanner scan = new Scanner(System.in);
1312
System.out.println("Enter a number: ");
1413
int n= scan.nextInt();
@@ -17,11 +16,9 @@ public static void main(String[] args)
1716
int sum=0;
1817
int r;
1918

20-
while(n>0)
21-
{
19+
while(n>0) {
2220
r=n%10;
2321
n=n/10;
24-
2522
sum=sum+r*r*r;
2623
}
2724
if(sum==m)

0 commit comments

Comments
 (0)