Answer:
This is the JAVA code:
import java.util.Scanner; // to capture user input
public class DrawHalfArrow{ // class declaration
public static void main(String[] args) { // main function starts here
Scanner scnr = new Scanner(System.in); //input reading
int arrowBaseHeight = 0; // variable for arrow base height
int arrowBaseWidth = 0; // variable for arrow base width
int arrowHeadWidth = 0; // variable for arrow head width
// prompts user for height, base width, and head width
System.out.println("Enter arrow base height: ");
arrowBaseHeight = scnr.nextInt(); // reads integer input
System.out.println("Enter arrow base width: ");
arrowBaseWidth = scnr.nextInt();
/* loop for asking user for arrow head width until it exceeds base width */
while (arrowHeadWidth <= arrowBaseWidth) {
System.out.println("Enter arrow head width: ");
arrowHeadWidth = scnr.nextInt(); }
//begin nested loop for base
//outer loop for outputting based on arrow base height
for (int i = 0; i < arrowBaseHeight; i++) {
//inner loop produces the stars
for (int j = 0; j <arrowBaseWidth; j++) {
System.out.print("*"); } //prints stars
System.out.println(); }
//used for the width of the arrowhead
int k = arrowHeadWidth;
//outer loop for the head height
for (int i = 1; i <= arrowHeadWidth; i++)
{ for(int j = k; j > 0; j--) {//inner loop for stars
System.out.print("*"); } //print stars
k = k - 1;
System.out.println(); } } } //marks end of asterisks for a new line
Explanation:
The code prompts for arrow dimensions, including height, base width, and head width. The program verifies that the head width must be larger than the base width through a condition. This loop instigates until the user provides a valid head width.
The loop manages the output of the arrow base corresponding to the specified height. Thus point (1) is fulfilled.
A nested loop is utilized to present an arrow base matching the defined width. The inner loop creates stars, establishing the width for the base, while the outer loop iterates according to the specified height. This satisfies point (2).
A temporary variable, k, saves the initial arrow head width for necessary adjustments.
The final nested loop outputs an arrow head corresponding to the specified width with stars. Therefore, point (3) is achieved.
The value of k decreases by 1 for each execution of the nested loop, ensuring each subsequent line contains fewer stars.
The output screenshot is attached.