-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrongNum.java
More file actions
44 lines (33 loc) · 909 Bytes
/
Copy pathArmstrongNum.java
File metadata and controls
44 lines (33 loc) · 909 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
/*
* PROGRAM : To check an integer as ARMSTRONG or not using a method with run-time-input through Scanner class
* FILE : ArmstrongNum.java
* CREATED BY: Santosh Hembram
* DATED : 09-09-20
*/
import java.util.*;
class ArmstrongNum{
public static void main(String[] args) {
int num;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
num = sc.nextInt();
if( (isArmstrong(num)) == 1 )
System.out.println(+num+" is an Armstrong Number");
else
System.out.println(+num+" is not an Armstrong Number");
}
public static int isArmstrong(int num1) {
int temp,digit,sum=0;
temp = num1;
while(num1!=0)
{
digit = num1 % 10;
sum = (digit * digit * digit) + sum;
num1 /= 10;
}
if(temp == sum)
return 1;
else
return 0;
}
}