3) Write a program named Full_XmasTree using a nested for loop that will generate the exact output. This program MUST use (ONLY) for loops to display the output below. For example the 1st row prints 1 star 2nd row prints 2, the 3rd row print 3 stars and so forth... This program is controlled by the user to input for the amount of row. "Prompt the user to enter the dimensions of the tree" A good test condition is the value of ten rows. (hint***)This program should account for white spaces print("* "). Remember the purpose of print() and println()

Respuesta :

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.
Ver imagen codiepienagoya

The Full_XmasTree program illustrates the use of loops

Loops are used for operations that must be repeated until a certain condition is met.

The Full_XmasTree program

The Full_XmasTree program written in Java where comments are used to explain each action is as follows:

import java.util.*;  

public class Full_XmasTree{        

public static void main(String as[])  {  

   //This creates a Scanner object

   Scanner input = new Scanner(System.in);

   //This prompts the user for the number of rows

   System.out.print("Rows: ");

   //This gets input the user for the number of rows

   int rows = input.nextInt();

   //The following iteration prints the full x-mas tree

   for (int i = 0; i < rows; i++){

       for (int j = rows - i; j > 1; j--){

           System.out.print(" ");

       }

       for (int j = 0; j <= i; j++){

           System.out.print("* ");

       }

       System.out.println();

      }

  }

}

Read more about loops at:

https://brainly.com/question/24833629