Kindly help me with this programm ques 11

package PracticePattern;

import java.util.Scanner;

public class PracticePattern11 {

public static void main(String[] args) {
	
	
	System.out.println("pattern 11");
	
	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 spaces 
		for(int csp=1;csp<=nsp;csp++)
		{
			
				System.out.print(" ");	
			
		}
		
		//work for stars 
		
		for(int cst = 1; cst <=nst ;cst ++)
		{
			
			if(rows%2==0 || cst%2!=0)
			{
				System.out.print(" ");
			}
			else if (rows % 2!=0 || cst % 2 ==0 )
			{
			System.out.print("*");
			
			}
			
		}
		
		
		//preparation
		System.out.println();
		nst=nst+2;
		nsp--;
		rows++;
		
		
	}
	
	
	
	

}

@Nitya_Somani Hi, sending you code for reference now do dry run it, that will help you learn more!

@Nitya_Somani Refer the code below!


Short and simple.
Also mark the query resolved and rate full
Happy coding!

1 Like