A. Beautiful Matrix // Solution in java

RMAG news
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));
}
}
}

}
}

Leave a Reply

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