
how to write a code that ask the user for the height of the triangle and prints the triangle using * eg if height is 3 it prints *

import java.util.*;
public class PatternExample {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter height: ");
int num=input.nextInt();
int p = num;
int q = 0;
for (int i = 0; i <= num; i++) {
for (int j = p; j>= 1; j-- )
System.out.print(" ");
p-=1;
for (int k = 1; k <= i; k++)
System.out.print ("* ");
System.out.println();
}
}
}