Output of array only on one line - any ideas why?

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Output of array only on one line - any ideas why?

1. Registered User
Join Date
Nov 2005
Posts
44

## Output of array only on one line - any ideas why?

Hi,

This is probably an incredibly simple question, but when I output the results of a sort method on an array list of 10,000 integers, it currently outputs the result as one long list of the 10,000 numbers on one line. They are sorted correctly, but the output of the sort is not suitable for easy presentation.

I currently can't see why this would happen.

My code is as follows:

Code:
```import simplejava.SimpleReader;

public class NumberListTester {

private int [] numbers;
private int arraySize, size;

public NumberListTester()
{
int[] numbers = new int[10000];
arraySize = numbers.length;
size = 0;
}

public NumberListTester(String fileName)
int size =0;
while (!file.finished())
{ size++;
}

numbers = new int[size];
arraySize = size;
for (int i = 0; i<size; i++)
}

public void add() //this is a version of the standard Bubble Sort algorithm//
{
int out, in;

for (out = numbers.length - 1; out > 1; out--)
// outer loop (backward)
for (in = 0; in < out; in++)
// inner loop (forward)
if (numbers[in] > numbers[in + 1]) // out of order?
swap(in, in + 1); // swap them
}

private void swap(int one, int two) {
int temp = numbers[one];
numbers[one] = numbers[two];
numbers[two] = temp;
}

public boolean contains( int n )
{
for( int i = 0; i < numbers.length; i++ )
if( numbers[ i ] == n )
return true;
return false;
}

public String toString()
{
String can = "";
for(int i=0; i<numbers.length; i++)
{
can += numbers[i];
}

return can;
}
}```
Any help or advice would be appreciated!

2. Registered User
Join Date
Nov 2005
Posts
44

## Re: Output of array only on one line - any ideas why?

Hi,

I'm glad to say the problem is now solved. A simple solution using + "\n" in the toString method.

Have a great weekend!!

#### Posting Permissions

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

 FAQ Latest Articles Java .NET XML Database Enterprise