Answer:
Following are the code to this question:
//import package
import java.util.*;
public class Full_XmasTree //defining class
{
// defining main method
public static void main(String as[])
{
int X,a,b; //defining integer variable
Scanner obx = new Scanner(System.in); // creating Scanner class object
System.out.print("Please enter: "); //print message
X = obx.nextInt(); // input value from user
for (a = 0; a < X; a++) //defining loop to print pattern
{
for (b = X - a; b > 1; b--)//use loop for print white space
{
System.out.print(" ");//print space
}
for (b = 0; b <= a; b++) // use loop to print values
{
System.out.print("* "); //print asterisk values
}
System.out.println(); //using print method for new line
}
}
}
Output:
please find the attachment.
Explanation:
In the given java code, a class "Full_XmasTree" is declared, in which the main method is declared, inside this method three integer variable "X, a, and b", in this variables "a and b" is used in a loop, and variable X is used for user input.
- In the next line, the Scanner class object is created, which takes input in variable X, and for loop is used to print asterisk triangle.
- In the first for loop, use variable a to count from user input value, inside the loop, two for loop is used, in which first is used to print white space and second is used for the print pattern.