Java Online Compiler
Example: Half Pyramid Pattern in Java of Stars using For loop
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Half Pyramid Pattern in Java of Stars using For loop import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int r = 0, i, j; // r - denotes the number of rows System.out.println("-----To print the half pyramid enter the number of rows-----"); r = in.nextInt(); System.out.print("\n"); for (i = 1; i <= r; ++i) { for (j = 1; j <= i; ++j) System.out.print("* "); System.out.print("\n"); } } }
10
Output
Clear
ADVERTISEMENTS