Skip to content

Instantly share code, notes, and snippets.

@pepet96
Created January 29, 2014 13:35
Show Gist options
  • Save pepet96/8688103 to your computer and use it in GitHub Desktop.
Save pepet96/8688103 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Array{
public static void main (String [] args){
Scanner input = new Scanner (System.in);
int numbers, numbers2;
numbers = input.nextInt();
int[] array = new int[numbers];
System.out.println("Now input each number you want.");
for (int counter=0;counter<array.length;counter++)
{
array[counter] = input.nextInt(); // aqui el array aggara cada integer del primer array
}
System.out.println("Input the AMOUNT of numbers you want to type in.");
numbers2=input.nextInt();
int[] array2 = new int[numbers2];
System.out.println("Now input each number you want.");
for(int counter=0;counter<array2.length;counter++)
{
array2[counter] = input.nextInt();
}
int[] merged= mergeArray(array, array2);
System.out.println(" ");
for (int counter : merged)
{
System.out.println(counter);
}
/* int[] reverse = reverseArray(array);
System.out.println(" "); // espacio para que no se confundan.
for(int counter = 0; counter<reverse.length;counter++){
System.out.println(reverse[counter]);
}
}
public static int [] reverseArray(int array[])
{
int[] respuesta = new int [array.length];
for(int counter=0;counter<array.length;counter++)
{
respuesta[counter] = array[array.length - counter -1];
}
return respuesta;
}
*/
}
public static int[] mergeArray(int array[], int array2[])
{
int[] respuesta= new int[array.length + array2.length];
for (int counter = 0;counter<array.length;counter++)
respuesta[counter] = array[counter];
for (int counter = 0; counter < array2.length; counter++)
respuesta[counter+array.length] = array2[counter];
return respuesta;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment