Unable to print pyramid of stars

ackage PracticePattern;

import java.util.Scanner;

public class PracticePattern9 {

public static void main(String[] args) {
	
	
	//pattern 9
	System.out.println("pattern 9 ");
		
	
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	
	
	int rows=1;
	int nst=1;
	int nsp=n-1;
	int nr = 2*n-1;
	
	
	while(rows<=n)
	{
		
		//work for space 
		for(int csp=1;csp<=nsp;csp++)
		{
			
			System.out.print(" ");
			
		}
		
		//work for stars 
		for(int cst=1;cst<=nr;cst++)
		{
			System.out.print("*" );
		}
		
		
		
	
		
		 
		//preparation 
		
		System.out.println();
		nst++;
		nsp--;
		rows++;
		
		
	}
	
	
	
}

}

Hey @Nitya_Somani
just change
//work for stars
for(int cst=1;cst<=nst;cst++)
{
System.out.print("*" );
}
//preparation
nst+=2;
correct code : https://ide.codingblocks.com/s/280440

1 Like