-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmstrong.java
More file actions
36 lines (31 loc) · 920 Bytes
/
armstrong.java
File metadata and controls
36 lines (31 loc) · 920 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
import java.util.Scanner;
public class armstrong {
public static int strong(int n){
int temp = n;
int digits = 0;
int sum = 0;
while(n>0){
n/=10;
digits++;
}
n = temp;
while(n>0){
int digit = n % 10;
sum += Math.pow(digit, digits);
n /= 10;
}
return sum;
}
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number to check weather the given number is armstrong or not: ");
int n = scanner.nextInt();
int sum = strong(n);
if (sum == n) {
System.out.println(n + " is an Armstrong number.");
} else {
System.out.println(n + " is not an Armstrong number.");
}
scanner.close();
}
}