Why is this sudoku code wrong , its giving solved sudoku for sample input given

static int printed=1;

public static void main(String[] args) {
	
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	
	int [][]arr=new int[n][n];
	
	for(int i=0 ; i<n ; i++)
	{
		for(int j=0 ; j<n ; j++)
			arr[i][j]=sc.nextInt();
		
	}

	
	solveSudoku(arr , 0 , 0);
}

//  i , j , are for iterations
static void solveSudoku(int[][] arr , int i , int j)				
{
	
	//  code will reach here only when sudoku is solved
	//  there are many solutions of one sudoku problem
	//  but we have to print one silution onlu thats why
	//  printed variable is used
	//  printed will tell how many soln we will be printing
	if(i==arr.length && printed==1)									
	{		
		for(int k=0 ; k<arr.length ; k++)
		{
			for(int l=0 ; l<arr.length ; l++)
			System.out.print(arr[k][l]+" ");
			System.out.println();
		}
		
		printed++;
		return;
	}
	
	
	// at this stage sudoku is solved
	// so we are returning 
	if(i==arr.length) return;
	
			
	//  entering loop
	while(j<arr.length)
	{
	
		
		// if element is already there then we dont need to change it
		if(arr[i][j]==0)
		{
			
			// trying for every number
			for(int k=1 ; k<=9 ; k++)
			{
				
				// if (k) is present or not at i'th row
				boolean presentR=searchR(arr , i , k);
				
				// if (k) is present or not at j'th column
				boolean presentC=searchC(arr , j , k);
				
				// if not present then fill element
				if(!presentR && !presentC)
				{
					arr[i][j]=k;
					
					// moving to next column
					solveSudoku(arr , i , j+1);
					
					// backtracking , reversing every change we made
					arr[i][j]=0;
					
					// if sudoku is once solved , then no need to solve again
					if(printed>1) return;
				}
				
			}
			
			// if no element was suitable for filling , 
			// we return to previous column and change that element
			if(arr[i][j]==0) return;
		}
		
		j++;
	
	}
	
	
	
	// i'th row is filled , moving to i+1'th row
	if(j==arr.length)
	{
		solveSudoku(arr , i+1 , 0);
		return;
	}
	
}



// searching element in row
static boolean searchR(int [][] arr , int i , int k)
{
	boolean present =false;
	
	for(int l=0 ; l<9 ; l++)
	{
		if(arr[i][l]==k)
		{
			present=true;
			break;
		}
	}
	
	return present;
	
}


// searching element in column
static boolean searchC(int[][] arr , int j , int k)
{
	boolean present =false;
	
	for(int l=0 ; l<9 ; l++)
	{
		if(arr[l][j]==k)
		{
			present=true;
			break;
		}
	}
	
	return present;
}

@Himanshu-Jhawar-2273952536067590,

Input:

9
5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 0 0 2 0 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 9 0 0 5
0 0 0 0 8 0 0 7 9

Correct answer:

5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 5 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9

Your answer:
5 3 1 2 7 6 4 9 8
6 2 3 1 9 5 8 4 7
1 9 8 3 4 7 5 6 2
8 1 2 7 6 4 9 5 3
4 7 9 8 5 3 6 2 1
7 4 5 9 2 8 3 1 6
9 6 7 5 3 1 2 8 4
2 8 6 4 1 9 7 3 5
3 5 4 6 8 2 1 7 9

Before assigning a number, you have to check whether it is safe to assign. Basically check that the same number is not present in the current row, current column and current 3X3 subgrid.

You are not checking in the 3x3 subgrid, hence the error.