-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprinklerSystem.java
More file actions
69 lines (66 loc) · 1.64 KB
/
SprinklerSystem.java
File metadata and controls
69 lines (66 loc) · 1.64 KB
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
66
67
68
69
package Composition;
import java.awt.event.ItemEvent;
import java.lang.reflect.Array;
import java.util.Arrays;
public class SprinklerSystem {
private String valve1, valve2, valve3, valve4;
private WaterSource source = new WaterSource();
private int i;
private float f;
public String tostring() {
return
"valve1 = " + valve1 + " " +
"valve2 = " + valve2 + " " +
"valve3 = " + valve3 + " " +
"valve4 = " + valve4 + "\n" +
"i = " + i + " " + "f = " + f + " " +
"source = " + source;
}
public static void main(String[] args) {
//SprinklerSystem sprinklers = new SprinklerSystem();
//System.out.println(sprinklers);
//print
int p[]= {10, 20, 20, 10, 10, 30, 50, 10, 20,20};
new SprinklerSystem().data(p);
}
public void data(int a[]) {
Arrays.sort(a);
int parcount=0,count=0;
int j=0,k=0;
for(int data:a)
System.out.print(data+" ");
System.out.println(" ");
while(true){
if(k==a.length){
System.out.print(parcount);
if(parcount%2==0) {
count=(parcount/2)+count;
System.out.println(":-> "+(parcount/2));
}else {
count=((parcount-1)/2)+count;
System.out.println(":-> "+((parcount-1)/2));
}
parcount=0;
break;
}
else if(a[k]==a[j]){
parcount+=1;
j=k;
k++;
}
else {
System.out.print(parcount);
if(parcount%2==0) {
count=(parcount/2)+count;
System.out.println(":-> "+(parcount/2));
}else {
count=((parcount-1)/2)+count;
System.out.println(":-> "+((parcount-1)/2));
}
parcount=0;
j=k;
}
}
System.out.println("Pair Count "+count);
}
}