File: Execute.java
--------------------------------------------------------------------------------------
package org.developersbrain.Solutions;
public class Execute {
public static int min(int[] arrList){
int minV1=0;
int minV2=0;
int aLen=arrList.length;
minV1=arrList[0];
minV2=arrList[aLen-1];
for(int i=0,j=aLen-1;i<=aLen/2;i++,j--){
if(minV1 > arrList[i]){
minV1=arrList[i];
}
if(minV2 > arrList[j]){
minV2=arrList[j];
}
}
if(minV2<=minV1){
return minV2;
}else{
return minV1;
}
}
public static int max(int[] arrList){
int minV1=0;
int minV2=0;
int aLen=arrList.length;
minV1=arrList[0];
minV2=arrList[aLen-1];
for(int i=0,j=aLen-1;i<=aLen/2;i++,j--){
if(minV1 < arrList[i]){
minV1=arrList[i];
}
if(minV2 < arrList[j]){
minV2=arrList[j];
}
}
if(minV2>=minV1){
return minV2;
}else{
return minV1;
}
}
public static void main(String[] args) {
int[] a={15,16,1,2,3,9,16,13,22,200,34,56,3,0,999,89,-1,-2,-99};
for(int l:a) System.out.print(l+" ");
System.out.println();
System.out.println("Minimum:"+min(a));
System.out.println("Maximum:"+max(a));
}
}
Output:
-------------------------
Minimum:-99
Maximum:999
Comments
Post a Comment