Matrix search no output

i used the same approach as u have used in the editorial soln. but there is nothing in the output section…please help
CODE:
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int i,j;
int a[][]=new int[n][m];
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
a[i][j]=sc.nextInt();
}
}
int ser=sc.nextInt();
if(ser<a[0][0] || ser>a[n-1][m-1])
{
System.out.println(“0”);
}
else
{
int r=0;
int c=m-1;
while(r < m-1 && c>=0)
{
if(a[r][c]<ser)
r++;
else if(a[r][c]>ser)
c–;
else
System.out.println(“1”);
}
}
}
}

3 3
3 30 38
44 52 54
57 60 69
62

consider this given tc…62 is greater than 3 and 62 is less than 9 so your code will go and search 62 in the matrix…if you find 62 then you print 1 BUT IF YOU DONT FIND 62…then in that case you have to print 0…
comparing values with arr[0][0] and arr[m-1][n-1] will handle cases which dont lie in this range but what about those case which lie in this range BUT are still not present in the matrix…thus print 0 if you dont find 62…

the while loop condition should be r<m and not r<m-1…

i am attaching the modified code for your reference

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.