Star Triangle
Completed
Read n and print a right triangle of stars with n rows (row i has i stars).
Input
One integer.
Output
n rows.
Example
Input
4
Output
* ** *** ****
Editor
Java
Hints
The inner loop runs i times on row i.
Solution explanation
Nested loops: the outer one picks the row, the inner one fills it.
Show solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
System.out.print('*');
}
System.out.println();
}
}
}