+ 1
Print 2D arrays using new line
5 Antworten
+ 1
See this :
https://code.sololearn.com/cSm6jciQZwou/?ref=app
it includes using for loop also....
https://www.sololearn.com/Discuss/2463038/?ref=app
Hope thes helps....
0
Is this not proper way to output 2d array..
Use 2 loop, one for traversing rows, one for columns then print inside loop..
0
but not supported solo learn
0
Is this full code? Today I have codes are truncating to my side while loading.. If this is your full code, then you are not closed your comment last.
Add */ at end and run..
use \n for new line, not /n
0
class Program {
public static void main(String[] args) {
int[][] sample = {{1, 2, 3},{4, 5, 6}};
System.out.print("{");
for(int i = 0; i < sample.length; i++) {
if (i + 1 < sample.length) {
System.out.print("{");
} else {
System.out.print("\n{");
}
for(int j = 0; j < sample[i].length; j++) {
if (j + 1 < sample[i].length) {
System.out.print(sample[i][j] + ",");
} else {
System.out.print(sample[i][j]);
}
}
System.out.print("}");
}
System.out.print("}");
}
}
/*Q: can any print this output:
{ {1 , 2 , 3}
{4 , 5 , 6} } */