-
Notifications
You must be signed in to change notification settings - Fork 0
/
minMaxSum.txt
44 lines (40 loc) · 1.13 KB
/
minMaxSum.txt
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
static void miniMaxSum(int[] arr) {
int min=0; int minPos=0;
int max=0; int maxPos=0;
long minSum=0;
long maxSum=0;
min=arr[0];
max=arr[0];
for(int i=1;i<arr.length;i++){
if(arr[i]<min){
min=arr[i];
minPos=i;
}
if(arr[i]>max){
max=arr[i];
maxPos=i;
}
}
if(min==max){
if(minPos==maxPos){
for(int k=0;k<arr.length;k++){
if(k!=minPos){
minSum+=arr[k];
maxSum=minSum;
}
}
}
}else{
for(int j=0;j<arr.length;j++){
if(arr[j]!=min){
maxSum+=arr[j];
}
if(arr[j]!=max){
minSum+=arr[j];
}
}
}
System.out.print(minSum);
System.out.printf("%1s","");
System.out.print(maxSum);
}