Print 2D arrays using new line | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
23rd Apr 2022, 5:25 PM
Madhusudan Bej
Madhusudan Bej - avatar
5 Answers
+ 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....
23rd Apr 2022, 5:44 PM
Jayakrishna 🇮🇳
0
Is this not proper way to output 2d array.. Use 2 loop, one for traversing rows, one for columns then print inside loop..
23rd Apr 2022, 5:31 PM
Jayakrishna 🇮🇳
0
but not supported solo learn
23rd Apr 2022, 5:37 PM
Madhusudan Bej
Madhusudan Bej - avatar
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
23rd Apr 2022, 5:41 PM
Jayakrishna 🇮🇳
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} } */
23rd Apr 2022, 6:16 PM
Madhusudan Bej
Madhusudan Bej - avatar