Saurabh Verma
Saurabh Verma

Reputation: 1544

How to iterate over a 2D array with a single loop?

how can we navigate through the two dimensional array without using nested loops.i.e by using only one loop.

 String ar[][]=new  String [3][4];

Upvotes: 13

Views: 6095

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272467

Here's a hint:

int i = 9;
System.out.println(i / 4);  // 2
System.out.println(i % 4);  // 1 

Upvotes: 20

Related Questions