Question

In: Computer Science

Using the IntelliJ IDEA tool, write a program that will print a Christmas tree with the...

Using the IntelliJ IDEA tool, write a program that will print a Christmas tree with the "*". The tree should have at least 10 lines. Look back at the birthday cake lab for examples of how to do this lab. Submit a screen shot of your output in the console (i.e. non REPL tool).


Solutions

Expert Solution

Answer = We need to print Christmas Tree like pattern. The source code provided below is in Java language. Comments are shown by "//" operator at the starting of line.

Source Code :

// import scanner to take input from user

import java.util.Scanner;

public class ChristmasTree {

    static void showChristmasTree(int num) {

        // start loop to print Christmas Tree

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

            for (int j = 0; j < 2 * num; j++) {

                if ((num - 1 - i) <= j && j <= (num - 1 + i)) {

                    System.out.print("*");

                } else {

                    System.out.print(" ");

                }

            }

            System.out.print("\n");

        }

        // End loop

    }

    // Main Class

    public static void main(String[] args) {

        System.out.println("Enter number of rows to print Christmas Tree Pattern");

        Scanner scan = new Scanner(System.in);

        int num = scan.nextInt();

        // Call function to print Christmas tree

        showChristmasTree(num);

        scan.close();

    }

}

Output : Save the file with file name "ChristmasTree.java" and follow below commands to see output.

command (i) = javac ChristmasTree.java

command (ii) = java ChristmasTree

The screenshot of output is:

Here program ask user to give input of total rows, then display tree.


Related Solutions

I am using IntelliJ IDEA with JavaFX to build a travel expensive calculator, but somehow it...
I am using IntelliJ IDEA with JavaFX to build a travel expensive calculator, but somehow it wouldn't calculate total expensive? It was working until I add the TextFieldListener because I need to make sure user only input either mile driven or airfareCost. Please help me figure out what I did wrong. import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import...
Write a program that will print out “W” using a character that a user provides. use...
Write a program that will print out “W” using a character that a user provides. use for loop statement. in java please
write a program that will print a truth table for p ^ ~q. Using C++ please.
write a program that will print a truth table for p ^ ~q. Using C++ please.
In the following Java program replace conditions in while loops to produce Christmas tree output. import...
In the following Java program replace conditions in while loops to produce Christmas tree output. import java.util.Scanner; public class Tree {     public static void main(String[] args)     {         int size;         Scanner scan = new Scanner(System.in);         System.out.print("Enter the size: ");         size = scan.nextInt();         int count = 0;         while (__________) //??? condition         {             int len = 0;             // print blanks             while (____________)//??? condition             {                 System.out.print(' ');                 len++;            ...
Write a Java program using jGRASP directions are as follows: Uses a while loop to print...
Write a Java program using jGRASP directions are as follows: Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider...
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
C++ Write a C++ program that implements a tree using a linked representation Each node will...
C++ Write a C++ program that implements a tree using a linked representation Each node will contain a single integer data element. Initialize the tree to contain 10 nodes. The program should allow for the insertion and deletion of data. The program should allow the user to output data in Preorder, Inorder and Postorder.
Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or...
Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or DecimalFormat Practice programming simple mathematical calculations Instructions: Samwise Gamgee has finally decided to submit his expense report for all of his adventures regarding his travels to Mordor. Part of those expenses are his stay at the Prancing Pony Inn located in Bree. You are to write a simple Java program which will generate an Invoice for his stay at the Inn. Your program should...
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
Write a program named subtract.asm that does the following using LC3 assembly language: Print a prompt...
Write a program named subtract.asm that does the following using LC3 assembly language: Print a prompt "PRESS TWO KEYS: " Note that the prompt MUST LOOK EXACTLY like the above, with a colon and a space after the word KEYS with no newline. Get a two key press from the user. Subtract the second characters ASCII code from the first characters ASCII code. If the result is positive, print the word POSITIVE. Turn in subtract.asm to the appropriate submission point...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT