Doubt in patterninvertedhourglass

package challanges;

import java.util.Scanner;

public class invertedhourglass {

public static void main(String[] args) {

		Scanner scn= new Scanner(System.in);
		int n=scn.nextInt();
		
		int nst=1;
		int nsp=2*n-1;
		
		int row=0;
		
		while(row<(2*n+1)) {
			
			for(int cst=1;cst<=nst;cst++) {
				System.out.print("*");
			}
			for(int csp=1;csp<=nsp;csp++) {
				
			   
			    
				System.out.print(csp);
				
				
			}
			for(int cst=1;cst<=nst;cst++) {
				System.out.print("*");
			}
			System.out.println();
			row++;
			if(row<=((2*n+1)/2)) {
				nsp=nsp-2;
				nst=nst+1;
				
			}
			else {
				nsp=nsp+2;
				nst=nst-1;
				
				
			}
		}


}

}
what is wrong in this code ???

Hey @harsh.hj
why are you printing "*"
actual pattern is this

             5                   5 
             5 4               4 5 
             5 4 3           3 4 5 
             5 4 3 2       2 3 4 5 
             5 4 3 2 1   1 2 3 4 5 
             5 4 3 2 1 0 1 2 3 4 5 
             5 4 3 2 1   1 2 3 4 5 
             5 4 3 2       2 3 4 5 
             5 4 3           3 4 5 
             5 4               4 5 
             5                   5 

so how can i print 5 in first column instead of stars

@harsh.hj
for(int cst=1;cst<=nst;cst++) {
System.out.print("* β€œ); // print value here
}
for(int csp=1;csp<=nsp;csp++) {
System.out.print(csp); // print space here
}
for(int cst=1;cst<=nst;cst++) {
System.out.print(”* "); // print value here
}

public static void main(String[] args) { Scanner scn= new Scanner(System.in); int n=scn.nextInt(); int nst=1; int nsp=2n-1; int val; int row=0; while(row<(2n+1)) { val=n; for(int cst=1;cst<=nst;cst++) { System.out.print(val); if (cst<=nst) { val–; } } for(int csp=1;csp<=nsp;csp++) { System.out.print(" "); } for(int cst=1;cst<=nst;cst++) { System.out.print(val); if (cst<=nst/2) { val–; } } System.out.println(); row++; if(row<=((2*n+1)/2)) { nsp=nsp-2; nst=nst+1; } else { nsp=nsp+2; nst=nst-1; } }

is this right code???

is this right code???
Answer Nope ;
I have changed your code
correct code :


dry this code .
Small changes here