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
Post a Comment