This question already has an answer here:
I've written this program to find 20 random numbers and store them into an array. Which then calls onto another class to print the array.( It was required to use two classes). Both of my programs compile fine however the output I recieve is
[I@12f55e8
instead of a list of numbers that were stored into the array. Can anyone tell me why this might be. Here is my program
Here is my displayArray method. It is just a method to print the array
**
* Displays array
* pre: array made
* post: array printed
*
*/
public class DisplayArrayAP
{
//
public static int[] toString (int[] array)
{
return(array);
}
}
Here is my main program
import java.util.*;
import java.io.*;
import java.util.Random;
public class TesterRandomAP
{
public static void main(String[] args) {
//creating a new display object with an array with 20 indexes
int[] array = new int[20];
DisplayArrayAP result = new DisplayArrayAP();
//creating a random object
Random rand = new Random();
//loop to access array
for(int index = 0; index < array.length; index++) {
//stores random number into array
array[index] = rand.nextInt(30)+1;
}
System.out.println(result.toString(array));
}
}
Aucun commentaire:
Enregistrer un commentaire