/* * Copyright (C) 2009 E.Albert, P.Arenas, S.Genaim, G.Puebla, and D.Zanardini * https://costa.ls.fi.upm.es * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package pubs; /** * A simple class with a method which concatenates two arrays of integers * into a new array. * * @author E.Albert, P.Arenas, S.Genaim, and G.Puebla * */ public class Concat { static int[] concat(int a[], int b[]) { int l1 = a.length; int l2 = b.length; int[] r = new int[l1+l2]; int i = 0; for (i=0;i<l1;i++){ r[i]=a[i]; } for (i=0;i<l2;i++){ r[i+l1]=b[i]; } return r; } public static void main(String[] args) { int[] first; int[] second; int[] result; // Prepare the test with 10 elements first = new int[10]; second = new int[10]; for (int k = 0; k < first.length; k++) { first[k] = k; } for (int k = 0; k < second.length; k++) { second[k] = k + first.length; } // Start first test result = concat(first,second); System.out.println("Result: "); /*for (int k = 0; k < result.length; k++) System.out.println(result[k]+" "); // Prepare the test with 50 elements first = new int[50]; second = new int[50]; for (int k = 0; k < first.length; k++) { first[k] = k; } for (int k = 0; k < second.length; k++) { second[k] = k + first.length; } // Start second test result = concat(first,second); System.out.println("Result: "); for (int k = 0; k < result.length; k++) System.out.println(result[k]+" "); // Prepare the test with 100 elements first = new int[100]; second = new int[100]; for (int k = 0; k < first.length; k++) { first[k] = k; } for (int k = 0; k < second.length; k++) { second[k] = k + first.length; } // Start the third test result = concat(first,second); System.out.println("Result: "); for (int k = 0; k < result.length; k++) System.out.println(result[k]+" "); */ } }