Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,790 answers

573 users

How to convert a 2D coordinate into 1D index in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        int[][] array2d =
        	{
        		{ 1,  2,   3,  6,  0},
        		{-5, -4,   0,  7,  9},
        		{ 1, 18, 100, 14,  6},
        		{ 9, 10,  27, 12, 13}
        	};

	    int cols = array2d[0].length;
    	
	    int i = 1, j = 3;
            
        int index = i * cols + j;
    
	    System.out.println(index);
    }
}





/*
run:
   
8
  
*/

 





answered Sep 18, 2023 by avibootz
edited Sep 19, 2023 by avibootz

Related questions

1 answer 25 views
1 answer 25 views
1 answer 26 views
1 answer 25 views
1 answer 26 views
...