-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayBalance
More file actions
40 lines (37 loc) · 950 Bytes
/
ArrayBalance
File metadata and controls
40 lines (37 loc) · 950 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
public class Main {
//Array sağ taraf ile sol tarafın toplamı eşit ise true değilse false
public static boolean denge(double [] list) {
double toplam=0;
double sonucSag=0;
double sonucSol=0;
int sira=0;
for(int i=0;i<list.length;i++) {
toplam=toplam+list[i];
}
double ortalama=toplam/2;
for(int i=0;i<list.length;i++) {
sonucSag=sonucSag+list[i];
if(sonucSag==ortalama) {
sira=i;
break;
}
}
for(int j=(list.length-1);j>sira;j--) {
sonucSol=sonucSol+list[j];
if(sonucSol==ortalama) {
return true;
}
}
return false;
}
public static void main(String[] args) {
double [] ornek1= {1,1,1,2,1};
double [] ornek2= {2,1,1,2,1};
double [] ornek3= {10,10};
double [] ornek4= {1,2,3,4,2};
System.out.println("ornek1:"+denge(ornek1));
System.out.println("ornek2:"+denge(ornek2));
System.out.println("ornek3:"+denge(ornek3));
System.out.println("ornek4:"+denge(ornek4));
}
}