Shaath - Deep Space Exploration
Single File Programming Question
Problem Statement
In a futuristic world of interstellar travel, a brilliant mathematician named Shaath is part of a critical mission for deep space exploration. While programming the navigation system for an interplanetary spacecraft, he encounters a matrix-based puzzle.
This puzzle involves identifying an identity matrix—a matrix that holds the key to aligning the spaceship with a safe travel trajectory. If even a single value in the matrix is off, the spaceship could be lost in the cosmic void!
As Shaath’s trusted assistant, your task is to develop a Java program that reads a square matrix and verifies whether it is an identity matrix using the civilized form of break statement. Your program must help ensure the astronauts reach their destination safely.
Input:
format :The first line of input consists of an integer 'n' representing the size of the square matrix.
The next 'n' lines contain 'n' integers each, separated by spaces, representing the elements of the square matrix.
Output:
format :The output prints "YES" if the given matrix is an identity matrix, and "NO" if it is not.
Refer to the sample output for format specifications.
Code constraints :
1 ≤ n ≤ 100
Each element of the matrix can be 0 or 1.
Sample test cases :
Input 1:
3 1 0 0 0 1 0 0 0 1
Output 1:
YES
Input 2:
3 1 0 0 0 0 1 0 0 1
Output 2:
NO