Write a program in java to display the pattern like right angle triangle with a number

Programs to print triangles using *, numbers, and characters


Example 1: Program to print half pyramid using *

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

Source code

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Example 2: Program to print half pyramid a using numbers

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Source Code

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Example 3: Program to print half pyramid using alphabets

A
B B
C C C
D D D D
E E E E E

Source Code

public class Main {

  public static void main(String[] args) {
    char last = 'E', alphabet = 'A';

    for (int i = 1; i <= (last - 'A' + 1); ++i) {
      for (int j = 1; j <= i; ++j) {
        System.out.print(alphabet + " ");
      }
      ++alphabet;

      System.out.println();
    }
  }
}

Programs to print inverted half pyramid using * and numbers


Example 4: Inverted half pyramid using *

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

Source Code

public class Main {

  public static void main(String[] args) {
    int rows = 5;

    for (int i = rows; i >= 1; --i) {
      for (int j = 1; j <= i; ++j) {
        System.out.print("* ");
      }
      System.out.println();
    }
  }
}

Example 5: Inverted half pyramid using numbers

1 2 3 4 5
1 2 3 4 
1 2 3
1 2
1

Source Code

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Programs to display pyramid and inverted pyramid using * and digits


Example 6: Program to print full pyramid using *

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Source Code

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Example 7: Program to print pyramid using numbers

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Source Code

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Example 8: Inverted full pyramid using *

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Source Code

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Example 9: Print Pascal's triangle

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Source Code

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Example 10: Print Floyd's Triangle.

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

Source Code

public class Main {

  public static void main(String[] args) {
    int rows = 5;

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

How to print right angle triangle pattern in Java?

import java. util. Scanner;.
class RightTriangle {.
public static void main(String args[]).
Scanner sc = new Scanner(System. in);.
int n=sc. nextInt();.
int a, b;.
for(a = 0; a < n; a++) {.

How to print a triangle with numbers in Java?

import java.util.Scanner;.
public class RightPascalTrianglePattern..
public static void main(String[] args).
int i, j, rows;.
Scanner sc = new Scanner(System.in);.
System.out.print("Enter the number of rows you want to print: ");.

How to print 1 12 123 in Java?

for(int i=1;i<=size;i++) // first loop which is used to print the series up to size. for(int j=1;j<=i;j++) // second loop which prints the one line elements. 1 12 123 1234 12345. ( Here space means line change).

How to print ABC pattern in Java?

Print Alphabet Pattern in Java.
Print Alphabet Pattern in Java. class AlphabetsDemo { public static void main(String args[]) { char ch; for( ch = 'a' ; ch <= 'z' ; ch++ ) System. ... .
Alphabet Pattern in Java. ... .
Java Program to Print Alphabet Pattern. ... .
Java Program to Print Alphabet Pattern..