In: Computer Science
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
*
***
*****
*******
*********
***********
*************
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.