Java Program:

- To print half triangle pattern using number

Example:

User Input: 3

Output:

1
1 2
1 2 3
import java.util.Scanner;

public class Pattern {

  public static void main(String[] args) {
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter number of rows : ");

    int rows;
    rows=userInput.nextInt();
    for(int i=1; i<=rows; i++) {
      for(int j=1; j<=i; j++) {
        System.out.print(j +" ");
      }
      System.out.print("\n");
    }

  }
}

Output:

  Enter number of rows : 4
  1
  1 2
  1 2 3
  1 2 3 4
Program
pattern

Main logic :

for(int i=1; i<=rows; i++) {  //rows : number of rows to print
  for(int j=1; j<=i; j++) {
    System.out.print(j +" ");
  }
  System.out.print("\n");
}
Concept

Coming Soon !

Quick
Tutorial

Quote

Make bold choices and make mistakes. It’s all those things that add up to the person you become.