티스토리 뷰

public class ComputeMaxnum {

static final int OVERFLOW = -999999;


static int max(int[] arr) {


if (arr == null) {

return OVERFLOW;

} else if (arr.length == 0) {

return OVERFLOW;

} else {


int max = 0;

for(int i=0;i<arr.length;i++){

if(max < arr[i]){

max = arr[i];

}

}

return max;

}

}


public static void main(String[] args) {

// TODO Auto-generated method stub


int[] data = { 24, 2, 942945, 1024, 457 };

System.out.println(java.util.Arrays.toString(data));

System.out.println("MaxValue = " + max(data));

System.out.println("MaxValue = " + max(null));

System.out.println("MaxValue = " + max(new int[] {}));

}


}





댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
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
글 보관함