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

• 11-12-2005, 06:02 PM
fulcanelli
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)     {  SimpleReader file = new SimpleReader(fileName);         int size =0;         int next = file.readInt();         while (!file.finished())         { size++;           next = file.readInt();         }                 file = new SimpleReader(fileName);         numbers = new int[size];         arraySize = size;         for (int i = 0; i<size; i++)             numbers[i] = file.readInt();     }         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! :confused:
• 11-12-2005, 06:15 PM
fulcanelli
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!! :)