実験課題5
Exercise 5(課題5) See the section 3.5.1. "Coupling". Show the source code to display intersection between given two arrays by modifying intersectAndPrint method in following figure and its execution result as a screenshot. Follow the instructions below to show the result.
- create the Java application project named
chapter3kadai5. - create
mainmethod to run the program inlucdingintersectAndPrintas below Figures in the project class. - take the screenshot of the execution result.
public static void intersectAndPrint(int[] a, int[] b) {
int[] dup = new int[a.length]; // 共通集合を表すリスト
int dupCnt = 0; // 共通集合の要素数
// 共通集合の導出処理
for (int j = 0; j < a.length; j = j + 1) {
for (int i = 0; i < b.length; i = i + 1) {
// 略
}
}
// 共通集合の表示処理
for (int i = 0; i < dupCnt; i = i + 1) {
// 略
}
}
public static void main(String[] args) {
int[] a1 = new int[]{1,2,3,4,5};
int[] a2 = new int[]{3,1,5,10,11};
intersectAndPrint(a1, a2);
}
1,3,5
(3.5.1.節をよく読み、プロジェクトchapter3kadai5を作成し、二つの配列の共通集合を表示するintersectAndPrintメソッドを下図のソースコードとの実行結果を元に作成し、ソースコードを示しなさい。ここで二つの配列の共通集合とは、二つの配列に共通して存在する要素からなる配列を意味する。例えば、配列a1が1,2,3,4,5でa2が3,1,5,10,11からなるとき、二つの配列の共通集合は1,3,5からなる配列である。)