A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a Java program to find the all positions of a given number in a given matrix. If the number not found print ("Number not found!")
Q:

Write a Java program to find the all positions of a given number in a given matrix. If the number not found print ("Number not found!")

0

Write a Java program to find the all positions of a given number in a given matrix. If the number not found print ("Number not found!")

Expected Output:

(0,2)

(1,0)

(2,1)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public class Solution {
 public static void main(String[] args) {
  int num = 3;
  int matrix[][] = {
   {2,5,3},
   {3,2,1},
   {1,3,5}
  };
  int r = matrix.length;
  int c = matrix[0].length - 1;
  int m = 0, n = 0;
  Boolean flag = false;
  while (m < r) {
   while (n <= c) {
    if (matrix[m][n] == num) {
     System.out.print("\n(" + m + "," + n + ")\n");
     flag = true;
    }
    n++;
   }
   m++;
   n = 0;
  }
  if (flag == false)
   System.out.print("Number not found!");
 }
}

Sample Output:

(0,2)

(1,0)

(2,1)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now