Hellp guys.
Im trying to do this following example.
What this program does, is that it joins and sorts two lists in the merge-method, and returns it to the main method.
however I'm running into issues while trying to work inside my method!
--> merge(int[],int) in Exercise07_31 cannot be applied to (int[],int[]) --> Exercise07_31.java:62: int cannot be dereferenced
and a bunch of more errors...
I don't seem to figure out where the error occurs, it should really be one little thing that i forgot. Isn't arrays integers, if so, how do i convert them and use them right ?
Can anyone please help me out? Thanks!
import java.util.*;
public class Exercise07_31
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
//Prompt for user input list 1:
System.out.print("Enter list1: ");
int a1 = input.nextInt();
//Set array:
int[] list1 = new int[a1];
//Prompt for array input:
for (int k = 0; k < a1; k++)
{
list1[k] = input.nextInt();;
}
//Prompt for user input list 2:
System.out.print("Enter list2: ");
int a2 = input.nextInt();
//Set array
int[] list2 = new int[a2];
//Prompt for array input
for (int j = 0; j < a2; j++)
{
list2[j] = input.nextInt();;
}
System.out.println("The merged list is ");
for (int l = 0; l < a3; l++)
{
System.out.print(merge(list1, list2) + ", ");
}
}
public static int[] merge(int[] list1, int list2)
{
int a3 = list1.length + list2.length;
//Creating array for join:
int[] list3 = new int[a3];
//join the lists to list3
for (int s = 0; s < list1.length; s++)
{
list3[s] = list1[s];
}
for (int h = 0; h < list2.length; h++)
{
list3[list1.length + h] = list2[h];
}
//Sort the lists:
int temp = 0;
for (int j = 0; j < list3.length; j++)
{
for (int k = 0; k < list3.length - 1; k++)
{
if(list3[k + 1] < list3[k])
{
temp = list3[k];
list3[k] = list3[k + 1];
list3[k + 1] = temp;
}
}
}
return list3;
}
}