# 두 배열의 교집합 <div class="embed-responsive embed-responsive-16by9"> <iframe src="https://www.youtube.com/embed/t8uM7135z4U" frameborder="0" allowfullscreen></iframe> </div> ## 문제 정렬된 두 정수 배열 A, B가 있다. A와 B에 교집합을 출력하시오. ## 출력 예 ``` A: 2 4 6 8 9 B: 1 3 4 5 6 8 9 교집합 => 4 6 8 9 ```
관련 강의로 이동

코드: java 1.8

import java.util.Arrays; public class FindIntersection { public static void main(String args[]) { // 배열 생성 int[] A = {2, 4, 6, 8, 9}; int[] B = {1, 3, 4, 5, 6, 8, 9}; // 배열 정보 출력 System.out.printf("A: %s\n", Arrays.toString(A).replaceAll("\\[|\\]|\\,", "")); System.out.printf("B: %s\n", Arrays.toString(B).replaceAll("\\[|\\]|\\,", "")); // 교집합 출력 printIntersection(A, B); } public static void printIntersection(int[] a, int[] b) { /* 해당 메소드를 완성하시오. */ System.out.print("교집합 => "); } }

입력

정답이 궁금하다면? 코드를 제출해보세요!