VERY WEIRD OUTPUT... HELP PLEASE?
Code :
public class array{
public static void main(String args []){
int[] list1 = {12, 32, 14, 35, 89, 16, 120};
int[] list2 = {9, 12, 8, 17, 120, 35, 36};
System.out.println("The intersection of both is " + Intersection(list1 , list2));
}
public static int[] Intersection(int list1[], int list2[]){
int[] section = new int[10];
int x = 0;
for(int i = 0; i < list1.length; i++){
for(int j = 0; j < list2.length; j++){
if((list1[i]) == (list2[j])){
section[i] = list1[i];
}
}
}
return section;
}
}
The output that I get for this is...
The intersection of both is [I@3bad086a
Process completed.
Re: VERY WEIRD OUTPUT... HELP PLEASE?
Quote:
The intersection of both is [I@3bad086a
The string : [I@3bad086a is from the toString method for an integer array. Decoding the string:
the [ is for a one dim array, the I is for data type int, the @... is the address in memory of the array in hex
Use the Arrays toString() method to display the contents of an array.
Re: VERY WEIRD OUTPUT... HELP PLEASE?
am sorry... I'm a beginner with arrays...
Would u please show me what to alter in my code... Thanks :D
Re: VERY WEIRD OUTPUT... HELP PLEASE?
Change the println(the array) to println(Arrays.toString(the array))
Re: VERY WEIRD OUTPUT... HELP PLEASE?
It says object toString can not be applied to int[] :/
Re: VERY WEIRD OUTPUT... HELP PLEASE?
Quote:
It says object toString can not be applied to int[]
What is the "it"?
Have you read the API doc for the Arrays class's toString method?
Show the code where it is giving the error and also post the full text of the error message.
Re: VERY WEIRD OUTPUT... HELP PLEASE?
Thanks alot problem solved ;)
I appreciate your time...