Question

In: Computer Science

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++;

            }

            len = 0;

            // print stars

            while (____________)//??? condition

            {

                System.out.print('*');

                len++;

            }

            System.out.println(); // go to next line

            count++;

        }

    }

}

Generated output for the size of 7:

Enter the size: 7

      *

     ***

    *****

   *******

*********

***********

*************

Solutions

Expert Solution

Code:

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 (count < size) //to print size of rows.
{
int len = 0;
// print blanks
while (len < size-count)//to print blanks before stars
{
System.out.print(' ');
len++;
}
len = 0;
// print stars
while (len < (2 * count + 1))//to print stars
{
System.out.print('*');
len++;
}
System.out.println(); // go to next line
count++;
}
}
}

output:

Note: my friend if you have any questions or queries comment below. i am happy to answer your all questions. i will sort out your queries. Thank you my friend.


Related Solutions

Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
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).
Please convert this java program to a program with methods please. import java.io.*; import java.util.*; public...
Please convert this java program to a program with methods please. import java.io.*; import java.util.*; public class Number{ public static void main(String[] args) {    Scanner scan = new Scanner(System.in); System.out.println("Enter 20 integers ranging from -999 to 999 : "); //print statement int[] array = new int[20]; //array of size 20 for(int i=0;i<20;i++){ array[i] = scan.nextInt(); //user input if(array[i]<-999 || array[i]>999){ //check if value is inside the range System.out.println("Please enter a number between -999 to 999"); i--; } } //...
In C program, Use "do...while" and "for" loops to write a program that finds all prime...
In C program, Use "do...while" and "for" loops to write a program that finds all prime numbers less than a specified value.
Write a program in java which is in main and uses no classes, methods, loops or...
Write a program in java which is in main and uses no classes, methods, loops or if statements Ask the user to enter their first name Ask the user to enter their last name Print their initials followed by periods (ie. Clark Kent = C. K.) Print the number of letters in their last name
Edit the given program to produce the following output in c++ mode: - Take in the...
Edit the given program to produce the following output in c++ mode: - Take in the name of a superhero & tell him how many villains he/she has to defeat today - The number of villains is randomly generated and should be a number between 11 and 42. - Use a seed of 7. Hint: Compile the program first before making edits What is your name? Hello Captain America There are 42 villains you need to defeat today Oops! one...
Write a program to perform the following actions: the language is Java – Open an output...
Write a program to perform the following actions: the language is Java – Open an output file named “Assign14Numbers.txt” – Using a do-while loop, prompt the user for and input a count of the number of random integers to produce, make sure the value is between 35 and 150, inclusive. – After obtaining a good count, use a for-loop to generate the random integers in the range 0 ... 99, inclusive, and output each to the file as it is...
Write a program that produces the following output using nested for loop in Java. ****** ////////////...
Write a program that produces the following output using nested for loop in Java. ****** //////////// ****** ***** //////////\\ ***** **** ////////\\\\ **** *** //////\\\\\\ *** ** ////\\\\\\\\ ** * //\\\\\\\\\\ * \\\\\\\\\\\\
I need a C++ program using while loops that counts the number of characters in a...
I need a C++ program using while loops that counts the number of characters in a sentence. The user inputs a sentence and then terminates the input with either '.' or '!'. And then it needs to count and display the number of a's, e's, i's, o's, u's, and consonants. The program should read both lower and upper case. They don't want us using switch statements or string operators, and want us to us if else if statements. I have...
JAVA PROGRAM Create a Binary Search Tree with the following elements in the order mentioned below:...
JAVA PROGRAM Create a Binary Search Tree with the following elements in the order mentioned below: 5, 85, 89, 3, 2, 8, 65, 92 Print the Pre-order of this tree Print the height and the balance factor of the nodes in the order they were inserted (5, 85, 89, 3, 2, 8, 65, 92) in the form of a table with three columns and 9 rows. Use column headers “Node”, “Height”, and “Balance Factor” for the three columns respectively. Use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT