0

I have 2d array that looks like this

0,7,0
7,3,3
8,0,3

I want to print such that the output looks like this(in non hard-coding way)

1st loop
0,7,0
7
8
2nd loop
0,7,0
  3
  0
3rd loop
0,7,0
    3
    3 
4th loop
0
7,3,3
8
5th loop 
  7
7,3,3
  0
6th loop
    0
7,3,3
    0
7th loop
0
7
8,0,3
8th loop
  7
  3
8,0,3
9th loop
    0
    3
8,0,3

I have no idea how should I code. Please give me tips. Thanks

2
Contributors
1
Reply
17
Views
2 Years
Discussion Span
Last Post by stultuske
0

actually, this is not that difficult.
what you need to do first, is to check whether you need to write it in one single loop, or are allowed to use nested loops, and whether or not the array will always be

int[x][x]

for

int[x][y]

the implementation would be different.

if you look close, you'll see that the array you are working on, is a two dimensional way.

get the length of the array. iterate over the elements of each subarray, so, length x length iterations.
or, iterate over the original array (same nr of iterations, just not on the same array)

and print the correct information.

but the best way is to try and start yourself.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.