TLE Coming even after I used the exact same logic as video

Question - Move zeroes

Code -
import java.util.*;
public class Main {

public static void swap (int[] arr, int i, int j) {
	int temp = arr[i];
	arr[i] = arr[j];
	arr[j] = temp;
	return;
}

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

	int index = 0;
	for(int i=0; i<n;i++) {
		if(arr[i] != 0) {
			swap(arr, i, index);
			index++;
		}
	}

	for(int i=0; i<n ;i++) {
		System.out.print(arr[i] + " ");
	}

}

}

I am getting TLE for 2 cases even though I am using exact same code as the one in video. I have tried 3 logics

share code in cb ide