...

View Full Version : Array to String Help



Robertb724
02-02-2012, 02:00 AM
I am making a program where I have to display a graph of number ranges. The numbers are randomly generated. Right now it makes an array of 100 numbers. I need to convert this array to a string. When I run this it just prints [I@5570984c


import java.util.Random;
import java.util.Arrays;

public class NumberGraph
{
public static void main(String[] args)
{
int [] numbers = new int [101];
int num;
boolean numberIn = false;
int count;

for (int loop = 0; loop<numbers.length; loop++)
{
numbers[loop]=-1;
//System.out.println(numbers[loop]);
}

do
{
num =(int)( Math.random()*101);
count = 0;
numberIn = false;
do
{
if (numbers[count]==num)
numberIn = true;
else if (numbers[count]==-1)
{
numbers[count]=num;
numberIn = true;
}
else
count++;
}
while(!numberIn);
}
while(count!=100);

numbers.toString();
System.out.println(numbers);

}
}



/** for (int trip = 0; trip<numbers.length; trip++)

System.out.println(numbers[trip]);

System.out.println("Total");
System.out.println(count);

}
}
*/

Fou-Lu
02-02-2012, 06:26 AM
.toString is typically linked to the object id regardless of what it is. I think most collections are actually the values, but not anything primitive like an array.
You need to iterate it:


for (int i : numbers)
{
System.out.println(i);
}

Or a standard for loop like you have.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum