-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExamin_the_Number.java
60 lines (59 loc) · 1.31 KB
/
Examin_the_Number.java
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
56
57
58
59
60
//Read Description for question
import java.util.*;
class Main
{
public static boolean isArmstrong(int n)
{
int n1,r,sum=0;
n1=n;
while(n>0){
r=n%10;
sum+=(r*r*r);
n=n/10;
}
if(sum==n1)
return true;
else
return false;
}
public static boolean isPerfect(int n)
{
int sum=0;
for(int i=1;i<n;i++){
if(n%i==0)
sum+=i;
}
if(sum==n)
return true;
else
return false;
}
public static void calcSum(int n)
{
int e=0,o=0,r;
while(n>0){
r=n%10;
if(r%2==0)
e+=r;
else
o+=r;
n=n/10;
}
System.out.println("Even Sum:"+e);
System.out.println("Odd Sum:"+o);
}
public static void main(String s[])
{
Scanner ip=new Scanner(System.in);
int num=ip.nextInt();
if(isArmstrong(num))
System.out.println("It is an Armstrong Number");
else
System.out.println("It is not an Armstrong Number");
if(isPerfect(num))
System.out.println("It is a Perfect Number");
else
System.out.println("It is not a Perfect Number");
calcSum(num);
}
}