OneCompiler

Java program to Print right angle triangle with numbers

300

Following program shows you how to print right angle triangle pattern with numbers using for loop

import java.util.*;
public class Pattern5 {
  public static void main(String[] args) {
    int i, j, rows;
    Scanner sc = new Scanner(System.in);
    rows = 7;
    for (i = 0; i <= rows; i++) {
      for (j = 1; j <= i; j++) {
        System.out.print(i + " ");
      }
      System.out.println();
    }
  }
}

Output:

1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
6 6 6 6 6 6 
7 7 7 7 7 7 7

Try it Online here https://onecompiler.com/java/3x739v4xv