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

Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Martins ad network.