Skip to content

Commit bca2c8b

Browse files
committed
Solution to print 3 digits ArmstrongNumber
1 parent c7ccd25 commit bca2c8b

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package Assignments;
2+
3+
import java.util.Scanner;
4+
5+
public class ArmstrongNumber {
6+
public static void main(String[] args) {
7+
8+
Scanner input = new Scanner(System.in);
9+
System.out.println("Enter the Number:");
10+
int n = input.nextInt();
11+
System.out.println(isArmStrongNumber(n));
12+
}
13+
14+
//Print all three digits Armstrong number
15+
static boolean isArmStrongNumber(int number){
16+
17+
int origianl = number;
18+
int sum = 0;
19+
20+
while (number > 0){
21+
22+
int reminder = number % 10;
23+
number = number/10;
24+
sum = sum + reminder*reminder*reminder;
25+
}
26+
27+
return sum == origianl;
28+
}
29+
}

0 commit comments

Comments
 (0)