-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomposite.java
58 lines (58 loc) · 937 Bytes
/
composite.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
import java.util.Scanner;
class composite
{
public static void main(String[] args)
{
try
{
int p_count = 0, c_count = 0;
int[] arr;
int size;
Scanner s = new Scanner(System.in);
System.out.print("Enter the no. of element: ");
size = s.nextInt();
arr = new int[size];
System.out.println("Enter the elements: ");
for (int i = 0; i < size; i++)
arr[i] = s.nextInt();
for (int j = 0; j < size; j++)
{
int count = 0;
if (arr[j] > 0)
{
for (int k = 1; k <= arr[j]; k++)
{
if (arr[j] % k == 0)
count++;
}
if (count > 2)
c_count++;
else
p_count++;
}
else if(arr[j]<0)
{
for (int k =arr[j]; k<=-1; k++)
{
if (arr[j] % k == 0)
count++;
}
if (count > 2)
{
c_count++;
}
else
{
p_count++;
}
}
}
System.out.println("No. of composite num: " + c_count);
s.close();
}
catch(Exception e)
{
System.out.println("Due to float or number exception");
}
}
}