Respuesta :
Answer:
The Java code is given below with appropriate comments for better understanding
Explanation:
// DisplayArrow.java
import java.util.Scanner;
public class DisplayArrow
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int arrowBaseHeight = 0;
int arrowBaseWidth = 0;
int arrowHeadWidth = 0;
int arrowHeadHeight = 0;
System.out.print("Enter arrow base height: ");
arrowBaseHeight = sc.nextInt();
System.out.print("Enter arrow base width: ");
arrowBaseWidth = sc.nextInt();
// loop to continue prompting the user for an arrow head width
// until the value is larger than the arrow base width.
while (arrowHeadWidth <= arrowBaseWidth)
{
System.out.print("Enter arrow head width: ");
arrowHeadWidth = sc.nextInt();
}
System.out.println();
// nested loop in which the inner loop draws the *’s, and the outer loop
// iterates a number of times equal to the height of the arrow base.
for (int i = 0; i < arrowBaseHeight; i++ )
{
for (int j = 0; j < arrowBaseWidth; j++ )
{
System.out.print("*");
}
System.out.println();
}
arrowHeadHeight = arrowHeadWidth;
// nested loop in which the inner loop draws the *’s, and the outer loop
// iterates a number of times equal to the height of the arrow head.
for (int i = 0; i < arrowHeadHeight; i++ )
{
for (int j = 0; j < arrowHeadWidth; j++ )
{
System.out.print("*");
}
arrowHeadWidth = arrowHeadWidth - 1;
System.out.println();
}
}
}
/*
output:
Enter arrow base height: 5
Enter arrow base width: 2
Enter arrow head width: 4
**
**
**
**
**
****
***
**
*
*/