Coding Challenge Day- 34: Problem 1: Print a Pyramid Pattern for a given number of rows

Hello! So I’m doing a 30 day coding challenge where I solve a few questions every day and thought of posting them here on my blog so that you guys can join the challenge too!

Welcome to Coding challenge Day 34: Problem 1! Be sure to post your answers, queries etc in the comments!

Actually I was just going through some of my 10th grade coding stuff and came across this. Couldn’t help but put this one here!

Problem: Print a Pyramid Pattern for a given number of rows as follows:

Sample: Rows=4
Output:

Solution:

package misc;

public class Pyramid_pattern {
	
	public static void main (String [] args){
		int rows=12, f=1;;
		
		for(int i=0; i<rows; i++,f+=2){
			int t=0;
			for(int j=0; j<rows-i-1; j++){
				System.out.print(" ");
			}
			
			while(t<f){
				System.out.print("*");
				t++;
			}
			
			System.out.println();
			
			
		}
	}

}

Happy Learning!!

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: