Skip to content

Instantly share code, notes, and snippets.

@IngeFrodo
Created April 15, 2020 00:06
Show Gist options
  • Save IngeFrodo/e32f51a87dbb9bc2846c51e7da7bbc00 to your computer and use it in GitHub Desktop.
Save IngeFrodo/e32f51a87dbb9bc2846c51e7da7bbc00 to your computer and use it in GitHub Desktop.
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
int[] a = new int[12];
int[] b = new int[12];
int[] c = new int[24];
System.out.println("Enter elements for firs array");
for (int i = 0; i < 12; i++) {
System.out.print("Enter element number " + (i + 1) + ":");
a[i] = scanner.nextInt();
}
System.out.println("Enter elements for second array");
for (int j = 0; j < 12; j++) {
System.out.print("Enter element number " + (j + 1) + ":");
b[j] = scanner.nextInt();
}
int i = 0;
int j = 0;
int k = 0;
for (int l = 0; l < 4; l++) {
for (int m = 0; m < 3; m++) {
c[k] = a[i];
k++;
i++;
}
for (int n = 0; n < 3; n++) {
c[k] = b[j];
k++;
j++;
}
}
System.out.println("The third array is: ");
for (int o = 0; o < c.length; o++) {
System.out.print(c[o] + ", ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment