Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lekciq;
- import java.util.Scanner;
- public class PositionsOf {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- // Read the dimensions of the matrix
- int rows = scanner.nextInt();
- int cols = scanner.nextInt();
- // Read the matrix
- int[][] matrix = new int[rows][cols];
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < cols; j++) {
- matrix[i][j] = scanner.nextInt();
- }
- }
- // Read the number to find in the matrix
- int numberToFind = scanner.nextInt();
- // Find and print positions of the number in the matrix
- boolean found = false;
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < cols; j++) {
- if (matrix[i][j] == numberToFind) {
- System.out.println(i + " " + j);
- found = true;
- }
- }
- }
- // Print "not found" if the number does not appear in the matrix
- if (!found) {
- System.out.println("not found");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement