Java program to print a given pattern. (stars)


Following is a Java program which prints a pyramid of numbers.

Example

 Live Demo

public class PrintingPyramidStars {
   public static void main(String args[]){
      int n,i,j;
      n = 5;
      for(i = 0; i<= n; i++) {
         for(j = 0; j<= i; j++){
            System.out.print("*"+" ");
         }
         System.out.print("
");       }    } }

Output

*
* *
* * *
* * * *
* * * * *
* * * * * *

Updated on: 30-Jul-2019

383 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements