java - How to print the results of an array in a single line? -


i know if me understand why array result not come in 1 single line. results of code below printed as:

[ 1 2 3 4 5 6 7 8 9 10 ] 

instead of [1 2 3 4 5 6 7 8 9 10].

any thoughts on doing wrong results not come in on line?

class rangeclass {      int[] makerange(int lower, int upper) {       int arr[] = new int[ (upper - lower) + 1 ];        for(int = 0; < arr.length; i++) {         arr[i] = lower++;       }       return arr;     }      public static void main(string arguments[]) {     int thearray[];     rangeclass therange = new rangeclass();      thearray = therange.makerange(1, 10);     system.out.println("the array: [ ");     for(int = 0; i< thearray.length; i++) {       system.out.println(" " + thearray[i] + " ");     }     system.out.println("]");     } }    

you can use shorter version:

int thearray[] = {1, 2, 3}; system.out.println(java.util.arrays.tostring(thearray)); 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -