DEV Community

Abdulla-kamal
Abdulla-kamal

Posted on

A. Beautiful Matrix // Solution in java

import java.util.Scanner;

public class Problem {
    public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
    int[][] nums = new int[5][5];
    for(int i = 0; i < nums.length; i++) {
    for(int j = 0; j < nums.length; j++) {
      nums[i][j] = input.nextInt();
    }
    }

    for(int i = 0; i < nums.length; i++) {
      for(int j = 0; j < nums.length; j++) {
        if(nums[i][j] == 1) {
          System.out.println(Math.abs(i-2) + Math.abs(j-2));
        }
      }
      }

    }
}


Enter fullscreen mode Exit fullscreen mode

Top comments (0)