Advertisement
deyanmalinov

02. Positions Of

May 24th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package DPM;
  2. import java.util.Scanner;
  3. public class Main {
  4.     public static void main(String[] args){
  5.         Scanner scan = new Scanner(System.in);
  6.         String[] matSize = scan.nextLine().split(" ");
  7.         int rows = Integer.parseInt(matSize[0]);
  8.         int cols = Integer.parseInt(matSize[1]);
  9.  
  10.         int[][] matrix = new int[rows][cols];
  11.  
  12.         for (int row = 0; row < matrix.length; row++) {
  13.             String[] line = scan.nextLine().split(" ");
  14.             for (int col = 0; col < matrix[0].length; col++) {
  15.                 matrix[row][col] = Integer.parseInt(line[col]);
  16.             }
  17.         }
  18.         int num = scan.nextInt();
  19.         boolean flag = false;
  20.         for (int i = 0; i < matrix.length; i++) {
  21.             for (int j = 0; j < matrix[0].length; j++) {
  22.                 if (matrix[i][j] == num){
  23.                     System.out.println(i + " "+ j);
  24.                     flag = true;
  25.                 }
  26.  
  27.             }
  28.  
  29.         }if (!flag){
  30.             System.out.print("not found");
  31.         }
  32.  
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement