-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExamine_Set_of_Int.java
65 lines (64 loc) · 1.39 KB
/
Examine_Set_of_Int.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
61
62
63
64
65
//Read Description for question
import java.util.*;
class Main
{
public static void checkPrime(int x)
{
int i,flag=0;
if (x==0||x==1){
System.out.println(x+" "+"is neither Prime nor Composite");}
else{
for(i=2;i<x/2;i++)
{ if(x%i==0) {
flag=1;
break; }
else
flag=0;
}
if(flag==0)
System.out.println(x+" "+"is a Prime Number");
else
System.out.println(x+" "+"is not a Prime Number");
}}
public static void checkPerfect(int x)
{
int sum=0;
if(x!=0){
for(int i=1;i<x;i++)
{
if(x%i==0)
sum+=i;
}
if(sum==x)
System.out.println(x);}
}
public static void printSum(int a[])
{
int e=0,o=0;
for(int i=0;i<a.length;i++){
if(a[i]%2==0)
e+=a[i];
else
o+=a[i];
}
System.out.println("Even Sum:"+e);
System.out.println("Odd Sum:"+o);
}
public static void main(String s[])
{
int n;
Scanner sp=new Scanner(System.in);
int i;
n=sp.nextInt();
int a[]=new int[n];
for(i=0;i<n;i++)
{
a[i]=sp.nextInt();
checkPrime(a[i]);
}
System.out.println("Perfect Numbers:");
for(i=0;i<n;i++)
checkPerfect(a[i]);
printSum(a);
}
}