-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmstrongNumber.java
More file actions
29 lines (29 loc) · 829 Bytes
/
armstrongNumber.java
File metadata and controls
29 lines (29 loc) · 829 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
import java.util.Scanner;
public class armstrongNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number to check for armstrong number: ");
int N = scanner.nextInt();
scanner.nextLine();
int temp = N;
int digit = 0;
int y;
int z =0;
while(temp != 0){
temp = temp / 10;
digit = digit +1;
}
temp = N;
while(temp != 0){
y = temp %10;
z = (int) (z + Math.pow(y , digit));
temp= temp/10;
}
if(z==N){
System.out.println(N + " is an Armstrong number.");
}else{
System.out.println(N + " is NOT an Armstrong number.");
}
scanner.close();
}
}