My result is coming in negative

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i=1,nst=1,ns=n-1, val;
while(i<=n) {
val=1;
int cs=1;
while(cs<=ns) {
System.out.print("\t");
cs++;
}
int cst=1;
while(cst<=nst) {
System.out.print(val+"\t");
cst++;
if (cst<= nst / 2)
val++;

		else 
			val--;
	}
	nst=nst+2;
	ns--;
	i++;
	System.out.println();
	
}

}}

result:
5
1
1 0 -1
1 2 1 0 -1
1 2 3 2 1 0 -1
1 2 3 4 3 2 1 0 -1

@laibaahsan27_1dfa992390072fd9 You just need to change
if (cst<= nst / 2)
val++;
else {
val–;
}
change this if condition to :
if(cst<= (nst / 2)+1)
And your code print exact output

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.