Computer Science, asked by GopalKrishna1, 1 year ago

how to display alternate elements in an 2d array whose columns and rows are unknown?

Answers

Answered by madanstudio02
0
When you mention it as a 2 d array, then there are two subscripts. One for row and another for column. If you don't know the number of columns or number of rows, then put an infinity loop for row and within which put another infinity loop for column. Try reading the content of the array using the row subscript and the column subscript.

if the corresponding position doesn't have a value, in case of Java, there will be an ArrayIndexOutOfBounds Exception, handle the exception, else continue reading the Array.

But this is not the right practice to do, when you specify the 2D array you should be aware of the rows and columns. If you are working with a data structure which has difficulty to assess the number of rows and columns, then you should go for collections.
Hope this helps.
Similar questions