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();
}
}
}

Categorized in:

Java

Tagged in:

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

Share Article:

Leave a Reply

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock