-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay19.java
More file actions
55 lines (38 loc) · 967 Bytes
/
Day19.java
File metadata and controls
55 lines (38 loc) · 967 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Day 19 coding Statement : Write a program to identify if the number is Armstrong number or not
Description
Get an input number from user and check whether the given number is an Armstrong number or not.
E.g. Let the number be 1634,
Here 1^4 + 6^4 + 3 ^4 + 4^4 = 1634
Therefore, this is an Armstrong number
Input
153
Output
Armstrong number
Input
121
Output
Not an Armstrong number
*/
import java.util.*;
public class Day19
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number : ");
int n=sc.nextInt();
int numberOfDigits=(int)Math.log10(n)+1;
System.out.println(numberOfDigits);
int val=n;
int sum=0;
while(val>0){
int rem=val%10;
sum=sum+(int)Math.pow(rem,numberOfDigits);
val=val/10;
}
if(sum==n)
System.out.println("The number is an Armstrong number");
else
System.out.println("The number is not an Armstrong number");
}
}