Question: Hello, I need the code below edited to fix the errors shown below. (JAVA) error 1. (bottom is correct version) input: 2 4 3 8

Hello,

I need the code below edited to fix the errors shown below. (JAVA)

error 1. (bottom is correct version)

input: 2 4 3 8

Enter arrow base height:

Enter arrow base width:

Enter arrow head width:

Enter arrow base width:

Enter arrow head width:

Exception in thread "main" java.util.NoSuchElementException

at java.util.Scanner.throwFor(Scanner.java:862)

at java.util.Scanner.next(Scanner.java:1485)

at java.util.Scanner.nextInt(Scanner.java:2117)

at java.util.Scanner.nextInt(Scanner.java:2076)

at DrawHalfArrow.main(DrawHalfArrow.java:20)

Expected output

Enter arrow base height:

Enter arrow base width:

Enter arrow head width:

Enter arrow head width:

****

****

********

*******

******

*****

****

***

**

*

error 2.

input 2 5 4 5 7

Your output

Enter arrow base height:

Enter arrow base width:

Enter arrow head width:

Enter arrow base width:

Enter arrow head width:

*****

*****

*******

******

*****

****

***

**

*

Expected output

Enter arrow base height:

Enter arrow base width:

Enter arrow head width:

Enter arrow head width:

Enter arrow head width:

*****

*****

*******

******

*****

****

***

**

*

import java.util.Scanner;

public class DrawHalfArrow {

public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in);

int arrowBaseHeight = 0;

int arrowBaseWidth = 0;

int arrowHeadWidth = 0;

System.out.println("Enter arrow base height:");

arrowBaseHeight = keyboard.nextInt();

// Modifiacation 4

while(true){

System.out.println("Enter arrow base width:");

arrowBaseWidth = keyboard.nextInt();

System.out.println("Enter arrow head width:");

arrowHeadWidth = keyboard.nextInt();

// loop until condition is satisfied.

if(arrowHeadWidth > arrowBaseWidth){

break;

// display if condition failed

}

}

System.out.println("");

// Modification 1 and 2.

/*

* 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 base.

*/

for(int i=0 ;i

for(int j=0; j

System.out.print("*");

}

System.out.println("");

}

// Modifiacation 3

/*

* 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.

*/

for(int k=arrowHeadWidth; k>0; k--){

for(int l=0; l

System.out.print("*");

}

System.out.println("");

}

return;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!