Why i am getting wrong pattern?

package PatternPrograms;

import java.util.Scanner;

public class Pattern5 {

public static void main(String[] args) {

	
	System.out.print("Pattern 5 ");
	
	// taking the value
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	
	// making rows
	
	int rows = 1;
	int nsp = n-1;
	int nst = 1;
	while ( rows <= n )
	{
		//work 
		
		//work for spaces
		
		int csp = 1;
		
		while(csp<=nsp)
		{
			System.out.print(" ");
			csp++;
		}
		
		// work for stars 
		
		int cst =1;
		
		while(cst <=nst )
		{
			System.out.println("*");
			cst++;
		}
		
		//prepation
		System.out.print("\n");

		nst++;
		nsp--;
		rows++;
		
		
	}


}

}

Hey @Nitya_Somani
Just a change
I commented in your code

1 Like