fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. int[][] mat = {{1,2,3,4},
  14. {5,6,7,8},
  15. {9,10,11,12},
  16. {13,14,15,16}};
  17.  
  18.  
  19. int key = 3;
  20. int[] oneDArray = new int[mat[0].length*mat[0].length];
  21.  
  22. int s = 0;
  23. for(int i = 0; i < mat[0].length; i ++)
  24. for(int j = 0; j < mat[0].length; j ++){
  25. oneDArray[s] = mat[i][j];
  26. s++;
  27. }
  28.  
  29.  
  30. int found = Arrays.binarySearch(oneDArray, key);
  31. if(found > -1)
  32. System.out.println(found/ mat[0].length + "," + found % mat[0].length); }
  33. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
0,2