Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: VERY WEIRD OUTPUT... HELP PLEASE?

  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    38
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default VERY WEIRD OUTPUT... HELP PLEASE?

    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.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: VERY WEIRD OUTPUT... HELP PLEASE?

    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.

  3. #3
    Member
    Join Date
    Jul 2011
    Posts
    38
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: VERY WEIRD OUTPUT... HELP PLEASE?

    Change the println(the array) to println(Arrays.toString(the array))

  5. #5
    Member
    Join Date
    Jul 2011
    Posts
    38
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: VERY WEIRD OUTPUT... HELP PLEASE?

    It says object toString can not be applied to int[] :/

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: VERY WEIRD OUTPUT... HELP PLEASE?

    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.

  7. #7
    Member
    Join Date
    Jul 2011
    Posts
    38
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: VERY WEIRD OUTPUT... HELP PLEASE?

    Thanks alot problem solved
    I appreciate your time...

Similar Threads

  1. ClassNotFoundException (bit weird)
    By chronoz13 in forum Exceptions
    Replies: 1
    Last Post: April 26th, 2011, 02:15 AM
  2. [SOLVED] Weird calendar.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 3rd, 2011, 08:19 PM
  3. Weird thing with JFrame
    By Brt93yoda in forum AWT / Java Swing
    Replies: 2
    Last Post: August 23rd, 2010, 05:00 PM
  4. Simple Input/Output program Acting weird
    By drexasaurus in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 19th, 2010, 02:15 PM
  5. Jsp weird problem
    By johniem in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 5th, 2010, 06:46 AM