반응형
✔️ 9개의 숫자를 배열에 입력한다. (배열 선언 후 반복문 이용)
✔️ 최댓값, 인덱스, 카운트 변수를 초기화해준다.
✔️ 반복문을 이용해 값비교를 해준다.
✔️ value값이 크다면 max에 넣어주고 index에 count값을 더한 후 넣어준다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class bj2562 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int arr[] = new int[9];
for(int i=0; i<arr.length; i++){
arr[i] = Integer.parseInt(br.readLine());
}
int max = 0;
int count = 0;
int index = 0;
for(int value : arr){
count++;
if(value > max){
max = value;
index = count;
}
}
System.out.println(max);
System.out.println(index);
}
}
반응형
'알고리즘 > 알고리즘:백준' 카테고리의 다른 글
[ 알고리즘 : 백준 ] 18018 : 최소, 최대 (0) | 2022.12.28 |
---|---|
[ 알고리즘 : 백준 ] 10871번 X보다 작은 수 (0) | 2022.12.26 |
[ 알고리즘 : 백준 ] 10807번 개수 세기 (0) | 2022.12.26 |
[ 알고리즘 : 백준 ] 14681:사분면 고르기 (0) | 2022.08.22 |
[ 알고리즘:백준 ] 2753:윤년 (0) | 2022.08.21 |