int[] integers = {4, 5, 7, 34, 52, 32, 67, 12, 44};
int maxVal = integers[0];
for (int i = 0; i < integers.length; i++) {
maxVal = integers[i] > maxVal ? integers[i] : maxVal;
}
System.out.println("최대값 : "+maxVal);
maxVal = integers[0];
for (int val : integers) {
maxVal = maxVal > val ? maxVal : val;
}
System.out.println("최대값 : "+maxVal);
int secondVal = integers[0];
for (int i = 0; i < integers.length; i++) {
if (integers[i] == maxVal) {
continue;
}else {
secondVal = integers[i] > secondVal ? integers[i] : secondVal;
}
}
System.out.println("두번째로 큰 값 :"+secondVal);
secondVal = integers[0];
for(int val : integers) {
if (val == maxVal) {
continue;
} else {
secondVal = secondVal > val ? secondVal : val;
}
}
System.out.println("두번째로 큰 값 :"+secondVal);
int [] maxVals = new int[2];
for(int val : integers) {
if(maxVals[0] < val) {
maxVals[1] = maxVals[0];
maxVals[0] = val;
}else if(maxVals[1] < val){
maxVals[1] = val;
}
}
System.out.println("두번째로 큰 값 :" + maxVals[1]);