class ArrayUtil{
public static int [] concat(int[] a,int[] b) {
int [] n = new int[a.length+b.length];
for(int i=0;i<n.length;i++) {
if(i<a.length) {
n[i] = a[i];
}
else {
n[i] = b[i-a.length];
}
}
return n;
}
public static void print(int[] a) {
System.out.print("[ ");
for(int i=0;i<a.length;i++) {
System.out.print(a[i]+" ");
}
System.out.print("]");
}
}
public class StaticEx {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] array1 = {1,5,7,9};
int[] array2 = {3,6,-1,100,77};
int[] array3 = ArrayUtil.concat(array1, array2);
ArrayUtil.print(array3);
}
}
결과
[ 1 5 7 9 3 6 -1 100 77 ]
'명품JAVA프로그래밍 > 4장 클래스와 객체' 카테고리의 다른 글
[명품JAVA프로그래밍] 4장 실습문제 11번 (0) | 2021.12.27 |
---|---|
[명품JAVA프로그래밍] 4장 실습문제 10번 (0) | 2021.12.27 |
[명품JAVA프로그래밍] 4장 실습문제 8번 (0) | 2021.12.27 |
[명품JAVA프로그래밍] 4장 실습문제 7번 (0) | 2021.12.27 |
[명품JAVA프로그래밍] 4장 실습문제 6번 (0) | 2021.12.27 |