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.
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.
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...
Using C++ code, write a program named q5.cpp to print the minimum of the sums x...
Using C++ code, write a program named q5.cpp to print the minimum of the sums x + y^3 and x^3 + y, where x and y are input by a user via the keyboard.
Write a program that uses a for loop to print One of the months of the...
Write a program that uses a for loop to print One of the months of the year is January One of the months of the year is February ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT