Hello guys, i'm a beginner on programming and currently making a program right now that will input 5 integer values for the first array and another 5 values for the second array, then merging a two lists of integers into a single list of integers. Store the merge list into another array in a sorted manner.
Example:
arrayOne = {5, 9, 3, 0, 2} arrayTwo = {7, 1, 8, 6, 4}
mergedArray: 5, 9, 3, 0, 2, 7, 1, 8, 6, 4
sortedArray: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class arrayMerge { /** * @param args * @throws IOException * @throws NumberFormatException */ public static void main (String[] args) throws NumberFormatException, IOException int[] arrayone = new int [4]; int[] arraytwo = new int [4]; int[] arrayMerge = new int[10]; BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in)); for (int ctr = 0; ctr < arrayOne.length; ctr++ ){ System.out.print("Enter 5 Numbers for the first array: "); arrayone[] = Integer.parseInt(dataIn.readLine()); // cannot resolve into a type, syntax error. System.out.print("array 2 {" + ctr + "}" + " = [" arrayone "]"); //syntax error, operator undefined. } for (int ctr = 0; ctr < arraytwo.length; ctr++) { System.out.print("Enter 5 Numbers for the second array: "); arraytwo[] = Integer.parseInt(dataIn.readLine()); // cannot resolve into a type, syntax error. System.out.print("array 2 {" + ctr + "}" + " = [" arraytwo "]"); //syntax error, operator undefined. } arrayMerge = arrayone + arraytwo; System.out.print (arrayMerge); } }
To be honest, what makes me confuse is on how to merge them, i tried many simple solutions for this problem that i understand so far and it appears that it didnt work quite well.