알고리즘/문자열, 정렬
[알고리즘] 등수구하기 with Java, 이중 for문
VIPeveloper
2022. 3. 5. 14:25
728x90
반응형

오늘 배운 것
1. 이중 for문
. for문을 순회할 때, 요소 하나를 기준으로 다른 배열요소들과의 관계성을 탐색하고싶을 때 사용하는 것 같다.
2. 문제 풀이
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int i = kb.nextInt();
int[] arr = new int[i];
for (int j = 0; j < arr.length; j++) {
arr[j] = kb.nextInt();
}
solution(i,arr);
}
private static void solution(int i, int[] arr) {
int[] answer = new int[arr.length];
for (int j = 0; j < arr.length; j++) {
int tmp = arr[j];
int i1 = 1;
for (int k = 0; k < arr.length; k++) {
if(tmp < arr[k]){
i1++;
}
}
answer[j] = i1;
}
for (int j = 0; j < answer.length; j++) {
System.out.print(answer[j]+" ");
}
}
}
728x90
반응형