Code is working in my machine. Why is it wrong in the online compiler?

package challenges_fundamentals_and_patterns;

import java.util.Scanner;

public class Pattern_DoubleSidedArrow {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner scn = new Scanner(System.in);

	// defining initial values
	int n = scn.nextInt();
	int nsp1 = n - 1; // space before digits
	int nsp2 = -1;// space between digits
	int nst = 1;
	int val = 1;

	// work using for loop

	for (int rows = 1; rows <= n; rows++) {
		for (int csp = 1; csp <= nsp1; csp++) {
			System.out.print(' ');
		}

		if (rows == 1) {
			System.out.print(val);
		}

		if (rows > 1 && rows < n) {
			for (int cst = 1; cst <= nst; cst++) {
				System.out.print(val);
				if(val>1) {val--;}
			}

			for (int csp = 1; csp <= nsp2; csp++) {
				System.out.print(' ');
			}

			for (int cst = 1; cst <= nst; cst++) {
				System.out.print(val);
				if(cst!=nst) {val++;}
			}
		}

		if (rows == n) {
			System.out.print(val);
		}

		// preparation

		System.out.println();
		if (rows <= n / 2) {
			nsp1 -= 2;
			nsp2+=2;
			val++;
			nst+=1;
		} else {
			nsp1+=2;
			nsp2-=2;
			val--;
			nst-=1;
		}

	}
	scn.close();
}

}