JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
try{
int N = new Scanner(System.in).nextInt();
//Input validation check
if (N < 2)
throw new NumberFormatException();
//Print if input is valid
printTriangle(N);
}
catch(NumberFormatException e){
System.out.print("Input is invalid");
}
}
public static void printTriangle(int max){
//Array grid to store values of the triangle
int[][] grid = new int[max][max];
//Line processing
for (int line = 0; line < max; line++){
//Column processing
for (int column = 0; column <= line; column++){
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run