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

This is Java programing. Complete Java program to produce the following output. interface Register{   void course();  ...
This is Java programing. Complete Java program to produce the following output. interface Register{   void course();   }   public class Interface1{      public static void main(String args[]){        Register c=new A();      c.course();      Register s=new B();      s.course();      } }   //output I'm taking A I'm taking B
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).
Write a Python program that uses while loops to perform the following steps and post the...
Write a Python program that uses while loops to perform the following steps and post the text code. Thanks a. Prompt the user to input two positive integers (no zero or negative). variables: firstNum and secondNum (firstNum must be less than secondNum). Validate the user's input; prompt the user again if firstNum is not less than secondNum (use while loop). b. Output all odd numbers between firstNum and secondNum. (use while loop). c. Output the sum of all even numbers...
Java Program. !ONLY USING WHILE LOOPS! (Completed but with errors, wanted to revise could anyone re-create...
Java Program. !ONLY USING WHILE LOOPS! (Completed but with errors, wanted to revise could anyone re-create this?) Write a program to keep track of the number of miles you have driven during an extended vacation and the number of gallons of gasoline you used during this time, recorded at weekly intervals. This vacation will last over several weeks (the precise number of weeks while making the program is unknown to the coder). Ask the user to enter the number of...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In 2020 the average cost of living/month (excluding housing) for a family of 4 in Pittsburgh was $3850 per month. Write a program to print the first year in which the cost of living/month is over $4450 given that it will rise at a rate of 2.1% per year. (Note:  this program requires no input). Program 2: discount A discount store is having a sale where...
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--; } } //...
Use nested for loops statements to generate the following output. (Java) -----1 ---22 --333 4444 Ignore...
Use nested for loops statements to generate the following output. (Java) -----1 ---22 --333 4444 Ignore the dashes formatting wouldnt allow for extra spaces behind the numbers
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 c++ using only while and for loops . Use of arrays and...
Write a program in c++ using only while and for loops . Use of arrays and functions is not allowed. Given the first value, generate the next ten terms of the sequence like 1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, … Explaination with code is required.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT