백준 3003 자바

·2022년 12월 2일
0

백준

목록 보기
6/16

여러 요소를 입력받고, 여러 요소를 뱉는다
개수 구하는거야 뭐.. 뺄셈으로 처리하면 되는거같다

처음 생각
배열을 선언해서 6개를 입력받고 반복문을 돌면서 필요한 개수들을 print로 출력한다

public class Num3003 {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int[] count = new int[6];
    int[] answer = {1, 1, 2, 2, 2, 8};
    for (int i = 0; i < count.length; i++) {
      count[i] = scanner.nextInt();
    }
    for (int i = 0; i < count.length; i++) {
      System.out.print(answer[i] - count[i] + " ");
    }
   }
}

이런 식으로 맞긴 했는데.. 입출력 파트인데 for문, 배열이 나와도 되는건가... 더 좋은 방법이 없을까..

profile
어?머지?

0개의 댓글