# Java Exercises: Find the all positions of a given number in a given matrix

## Java Basic: Exercise-194 with Solution

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!").

**Pictorial Presentation:**

**Sample Solution:**

**Java Code:**

```
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)

**Flowchart: **

**Java Code Editor:**

**Company:**
LinkedIn

** Contribute your code and comments through Disqus.**

**Previous:** Write a Java program that accept an integer and find the sum of all the elements from all possible subsets of a set formed by first n natural numbers.

**Next:** Write a Java program to check if three given side lengths (integers) can make a triangle or not.

**What is the difficulty level of this exercise?**

Test your Programming skills with w3resource's quiz.

## Java: Tips of the Day

**Java: Difference between StringBuilder and StringBuffer**

StringBuffer is synchronized, StringBuilder is not:

Ref: https://bit.ly/3rOJQuT

**Weekly Trends**- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises