fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class ReturnTwoValues
  6. {
  7. static class Position{
  8. int i;
  9. int j;
  10. }
  11.  
  12. static Position search(int[][] m, int x){
  13. Position pos= new Position();
  14. for(int i=0;i<m.length;i++)
  15. for(int j=0;j<m[i].length;j++)
  16. if(m[i][j] == x){
  17. pos.i = i;
  18. pos.j = j;
  19. return pos;
  20. }
  21. return null;
  22. }
  23.  
  24.  
  25. public static void main (String[] args) throws java.lang.Exception
  26. {
  27. int[][] matrix = new int[][]{
  28. {1, 2, 3},
  29. {4, 5, 6},
  30. {7, 8, 9},
  31. };
  32.  
  33. for(int x=1; x <= 11; x += 2) {
  34. Position pos = search(matrix, x);
  35. if(pos != null){
  36. System.out.println("matrix["+pos.i+"]["+pos.j+"] == "+x);
  37. } else {
  38. System.out.println("Value "+x+" not found.");
  39. }
  40. }
  41. }
  42. }
Success #stdin #stdout 0.08s 381184KB
stdin
Standard input is empty
stdout
matrix[0][0] == 1
matrix[0][2] == 3
matrix[1][1] == 5
matrix[2][0] == 7
matrix[2][2] == 9
Value 11 not found.