Answer:
Following are the program in java language that is mention below
Explanation:
import java.util.*; // import package
public class Half_XmasTree // main class
{
public static void main(String args[]) // main method
{
int k,i1,j1; // variable declaration
Scanner sc2=new Scanner(System.in); // create the object of scanner
System.out.println("Enter the Number of rows : ");
k=sc2.nextInt(); // Read input by user
for(i1=0;i1<k;i1++) //iterating the loop
{
for(j1=0;j1<i1;j1++) // iterating the loop
System.out.print(" ");
for(int r=k-i1;r>0;r--) //iterating loop
System.out.print("*"); // print *
System.out.println();
}
}
}
Output:
Following are the attachment of output
Following are the description of program
- Declared a variable k,i1,j1 as integer type .
- Create a instance of scanner class "sc2" for taking the input of the rows.
- Read the input of row in the variable "K" by using nextInt() method .
- We used three for loop for implement this program .
- In the last loop we print the * by using system.println() method.