Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My code is as follows import java.util.Scanner; public class DrawHalfArrow { public static void main(String[] args) { Scanner scnr = new Scanner(System.in);

My code is as follows

import java.util.Scanner;

public class DrawHalfArrow {
  public static void main(String[] args) {
     Scanner scnr = new Scanner(System.in);
     int arrowBaseHeight;
     int arrowBaseWidth;
     int arrowHeadWidth;
     
     System.out.println("Enter arrow base height:");
     arrowBaseHeight = scnr.nextInt();
     
     System.out.println("Enter arrow base width:");
     arrowBaseWidth = scnr.nextInt();
     
     System.out.println("Enter arrow head width:");
     arrowHeadWidth = scnr.nextInt();
     System.out.println("");
     
     // Draw arrow base (height = 3, width = 2)
      while (arrowHeadWidth <= arrowBaseWidth) {
         System.out.println("Enter arrow head width:");
         arrowHeadWidth = scnr.nextInt();
     }

     System.out.println();
     for (int i = 0; i < arrowBaseHeight; i++) {
         for (int j = 0; j < arrowBaseWidth; j++) {
             System.out.print("*");
         }
         System.out.println();
     }

     for (int i = arrowHeadWidth; i > 0; i--) {
         for (int j = 0; j < i; j++) {
             System.out.print("*");
         }
         System.out.println();
     }
  }
}

 

 

and this error


 

any help with what I did wrong would be appreciated, the problem for this code is below

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. (1 pt)

 

(2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the *'s, and the outer loop iterates several times equal to the height of the arrow base. (1 pt)

 

(3) Modify the given program to use a loop to output an arrow head of width arrowHeadWidth. Use a 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. (2 pts)

 

(4) Modify the given program to only accept an arrow head width that is larger than the arrow base width. Use a loop to continue prompting the user for an arrowhead width until the value is larger than the arrow base width. (1 pt)

5 Input 2 4 Your output starts Enter arrow base height: Enter arrow base width: Enter arrow head width: with ** ** ** ** ** Enter arrow base height: Enter arrow base width: Enter arrow head width: Expected output starts with ** ** ** ** **

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java How To Program Late Objects Version

Authors: Paul Deitel, Deitel & Associates

8th Edition

0136123716, 9780136123712

Students also viewed these Databases questions