- 1
How to print an array elements in a single line in java?
4 Respostas
+ 4
By single line I assume you want something that's already been made for you.
Then you can use toString in the Arrays class:
int[] ex = {3,2,1};
System.out.println(Arrays.toString(ex));
It's pretty much the same thing Rishci said, but probably without concatenation. (They likely used StringBuilder)
+ 2
use System.out.print() instead of System.out.println()
//example
class ABC
{
public static void main(String args[])
{
int a[]={1,2,3,4,5};
int l=a.length;//finds the length of the array
for(int i=0;i<l;i++)
System.out.print(a[i]+" ");
}
}
+ 1
Add each element to a string using +=.
0
thanks