Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By SurfMan

Thread: how to get results to human readable output?

  1. #1
    FOX427 is offline Member
    Join Date
    Jun 2011
    Posts
    54
    Rep Power
    0

    Default how to get results to human readable output?

    Hi All! I am writing a loop with here:
    Java Code:
    /**
     * Fills an array a with 10 random numbers between 1 to 100.
     * @author FOX
     *
     */
    import java.util.Random;
    
    public class RandomNumbers {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int[] a = new int[10];
    		Random generator = new Random();
    		for (int i = 0; i < a.length; i++)
    		{
    			a[i] = generator.nextInt(100)+1;
    		}
    		System.out.println(a);
    	}
    
    }
    after i run program it gives me this: [I@a431693
    How can we have human readable output? Thanks in advance.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    926
    Rep Power
    2

    Default Re: how to get results to human readable output?

    Loop through the array again and print the individual numbers, or use Arrays.toString().

  3. #3
    FOX427 is offline Member
    Join Date
    Jun 2011
    Posts
    54
    Rep Power
    0

    Default Re: how to get results to human readable output?

    I already did toString() method but got the same result, had to include this in the same loop above after assigning random numbers to array indexes as you said:
    System.out.println(a[i]); seems it is working fine now, thanks!

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    926
    Rep Power
    2

    Default Re: how to get results to human readable output?

    Note that I said: Arrays.toString(int[]), not a.toString(). Arrays.toString is a static method which is overloaded with lots of different parameters, which does the job as well. So you should write Arrays.toString(a);.
    FOX427 likes this.

  5. #5
    FOX427 is offline Member
    Join Date
    Jun 2011
    Posts
    54
    Rep Power
    0

    Default Re: how to get results to human readable output?

    It works! Thank you so much and sorry for not paying attention.

Similar Threads

  1. Help with Readable Interface
    By fatabass in forum New To Java
    Replies: 13
    Last Post: 02-06-2012, 08:15 PM
  2. output shows undesired results(advice ?)
    By jasperFernandes in forum New To Java
    Replies: 0
    Last Post: 03-10-2011, 02:32 AM
  3. Output console results to a HTML browser
    By JTS25 in forum New To Java
    Replies: 5
    Last Post: 11-04-2010, 06:25 PM
  4. Output to results file help!
    By javanator in forum New To Java
    Replies: 6
    Last Post: 04-18-2010, 01:59 AM
  5. Replies: 0
    Last Post: 11-06-2007, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •