Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with the following Java program. Use Method to solve the contest pro

ID: 3771308 • Letter: I

Question

I need help with the following Java program. Use Method to solve the contest problem

Description: How many bars do YOU have? Actually we'll tell you how many bars you have and how wide to make them and you will print out a picture of them. All the bars will have the same width. The smallest bar will be on the left and be a square made of X's, the next bar will be twice as tall as the first bar, the next bar will be three times as tall as the first bar, etc.

Input: There will be 2 integers input. The first will be the number of bars to draw (somewhere between 1 and 25). The next will be the width of each bar (which is also the height of the first bar), a number in the range 1,...,6. (You may rely on the user to enter appropriate values .)

Output : Display the bars with exactly one empty character position between adjacent bars, as shown below.

Example: In this example, the user input required 5 bars, each 3 characters wide.

Example run:

Enter the number of bars, and the width of each bar: 5   3

                XXX

                XXX

                XXX

            XXX XXX

            XXX XXX

            XXX XXX

        XXX XXX XXX

        XXX XXX XXX

        XXX XXX XXX

    XXX XXX XXX XXX

    XXX XXX XXX XXX

    XXX XXX XXX XXX

XXX XXX XXX XXX XXX

XXX XXX XXX XXX XXX

XXX XXX XXX XXX XXX

Explanation / Answer

import java.util.Scanner;

public class JavaProgram
{
public static void main(String args[])
{
int i, space, rows, k=0;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Number of Rows : ");
rows = scan.nextInt();
for(i=1; i<=rows; i++)
{
for(space=1; space<=(rows-i); space++)
{
System.out.print(" ");
}
while(k != (2*i-1))
{
System.out.print(" X ");
k++;
}
k = 0;
System.out.println();
}
}
}

thank you