If element is not present it print nothing

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);

	int r=sc.nextInt();
	int c=sc.nextInt();
	int arr[][]=new int[r][c];
	for(int i=0;i<r;i++)
	{
	for(int j=0;j<c;j++){
		arr[i][j]=sc.nextInt();
	}
	}
	int val=sc.nextInt();
	int rn=-1;

	for(int i=0;i<r;i++){
		if(val>=arr[i][0]&&val<=arr[i][c-1]){
			rn=i;
			break;
		}

	}
	if(rn==-1){
		System.out.println(0);
	
	}
	else{
	for(int j=0;j<c;j++){
		if(arr[rn][j]==val){
			System.out.println(1);
			break;
		}
	}

	}

}

}

sample test:
3 3
3 4 5 6
5 6 7 8
9 12 1 3
65

@Vipin_coder,
For the sample test case:
3 3
3 30 38
44 52 54
57 60 69
62

When you first iterate the rows, your rn becomes 2. Now if you iterate that row, the value is not present and it exits the loop. Now, there is no print statement after the loop. Hence not printing anything.

Suggested approach:

1.Let array be arr and target be the element to be found.
2.Iterate over each row
2.1  Iterate over each column in reverse order
      2.1.1 If arr[row][col]==target then break the loop and print 1
      2.1.2 if arr[row][col]>target then
                         col--;            //decrement  columns
      2.1.3 else  row++;    //increment rows 
3.If loop is not broken in between then it indicates that element is not present in arr .So print 0.

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.