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

# Thread: Problem with Random Numbers

1. ## Problem with Random Numbers

I'm working on this program where I create an array of random integers and use bubble sort to get them in order:

```package bubblesort;

import java.util.Random;
public class BubbleSort {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
final int size = 10;
int[] array = new int[size];

Random randomNumber = new Random();

for(int i=0; i<array.length; i++){
array[i] = randomNumber.nextInt(29);
}

int[] sortedArray = bubbleSort(array);
System.out.println(sortedArray);
}

static int[] bubbleSort(int[] numbers){
int n = numbers.length;

for(int pass=1; pass<=n; pass++){
for(int current=0; current<n-pass; current++){
if(numbers[current] > numbers[current+1]){
//swap
int temp = numbers[current];
numbers[current] = numbers[current+1];
numbers[current+1] = temp;
}
}
}
return numbers;
}
}```

instead of it outputting the sorted numbers I get an output of: [I@4669b7fe

any thoughts?

2. ## Re: Problem with Random Numbers

output of: [I@4669b7fe
That is the output from the toString() method for a int array. If you want to format an array for printing, use this:
`System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));`

3. ## The Following User Says Thank You to Norm For This Useful Post:

3sbwya (February 17th, 2013)

4. ## Re: Problem with Random Numbers

Thanks. That helped a ton