Kindly help me with this programm

package PracticePattern;

import java.util.Scanner;

public class PracticePattern12 {

public static void main(String[] args) 

{

	System.out.println("Pattern 12");
	
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	
	int rows = 1 ;
	int nsp = n-1;
	int nst = 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<=nst;cst++)
		{
			System.out.print("* !" );
		}
		
		
		
		//preparation 
		System.out.println();
		nsp--;
		nst++;
		rows++;
	}
	
	
	

}

}

Hey @Nitya_Somani
small changes

import java.util.Scanner;

public class Main {

public static void main(String[] args)

{

	System.out.println("Pattern 12");

	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();

	int rows = 1;
	int nsp = n - 1;
	int nst = 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 <= nst; cst++) {

mera change
if (cst % 2 != 0)
System.out.print("* “);
else
System.out.print(”! ");
}

		// preparation
		System.out.println();
		nsp--;
		nst+=2;
		rows++;
	}

}

}

1 Like