-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrong.java
More file actions
51 lines (36 loc) · 1006 Bytes
/
Copy pathArmstrong.java
File metadata and controls
51 lines (36 loc) · 1006 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
import java.util.Scanner;
import java.lang.*;
// 153 = 1*1*1 + 5*5*5 + 3*3*3 , 1634
public class Armstrong {
public static boolean isArmstrong(int num) {
int originalno = num;
int sum = 0;
int digitcnt = 0;
while(num>0)
{
num=num/10;
digitcnt++;
}
num = originalno;
while(num>0)
{
int digit = num%10;
sum += Math.pow(digit , digitcnt);
num = num/10;
}
return sum == originalno;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a no. to check ArmStrong No : " );
int number = sc.nextInt();
if (isArmstrong(number))
{
System.out.println("the given no. is armstrong no. ");
}else
{
System.out.println("not Armstrong");
}
sc.close();
}
}