Wednesday, September 11, 2019

Print * Patterns in Java

Print * Patterns in Java


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

   


Java Code:


public class PatternEx3 {

      public static void main(String[] args) {
            int row = 5;
            for (int i = 0; i <= 5; i++) {
                  // Printing i spaces at the beginning of each row

                  for (int j = 1; j <= i; j++) {
                        System.out.print(" ");
                  }

                  // Printing j *'s at the end of each row

                  for (int j = row; j > 0; j--) {
                        System.out.print("* ");
                  }

                  System.out.println();

                  // Decrementing the row

                  row--;
            }

      }

}

No comments:

Post a Comment

Create a Digital Clock using HTML and JavaScript

Create a Digital Clock using HTML and JavaScript  <! DOCTYPE html> < html > < head > <...

Followers

Search This Blog

Popular Posts