Design Patterns in Java where input n=4, output like

1
2 3
4 5 6
7 8 9 10 ?
  • Pattern is an underlying structure that organizes surfaces or structures in a consistent, regular manner. Pattern can be described as a repeating unit of shape or form.
  • Given a positive integer n.The problem is to print the pyramid pattern as designed the sample code is given below.

Sample Code

import java.io.*;
class Wikitechy {
 public static void main(String[] args) {
  int val = 1, n = 4;
  for (int i = 1; i <= n; i++) 
  {
   for (int j = 0; j < i; j++) 
   {
    System.out.print(val + " ");
    val++;
   }
   System.out.println();
  }
 }
}
Java

Categorized in:

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,