222k views
0 votes
Drawing a half arrow (Java) This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width. (1) Modify the given program to use a loop to output an arrow base of height arrowBaseHeight.

User Intra
by
7.4k points

1 Answer

7 votes

Final answer:

To modify the given program to output an arrow base of height arrowBaseHeight, you can use a loop. The loop should iterate a number of times equal to arrowBaseHeight. Inside the loop, you can print a line of asterisks or any other character to represent the arrow base.

Step-by-step explanation:

To modify the given program to output an arrow base of height arrowBaseHeight, you can use a loop. The loop should iterate a number of times equal to arrowBaseHeight. Inside the loop, you can print a line of asterisks or any other character to represent the arrow base. Here's an example:

public class Main {
public static void main(String[] args) {
int arrowBaseHeight = 4; // Replace with user input
int arrowBaseWidth = 5; // Replace with user input
int arrowHeadWidth = 3; // Replace with user input

// Output arrow base
for (int i = 0; i < arrowBaseHeight; i++) {
for (int j = 0; j < arrowBaseWidth; j++) {
System.out.print('*');
}
System.out.println();
}

// Output arrow head
for (int i = 0; i < arrowHeadWidth; i++) {
for (int j = 0; j <= i; j++) {
System.out.print('*');
}
System.out.println();
}
}
}

User Briba
by
7.9k points