1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
svlad2 [7]
4 years ago
11

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.
(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 a number of times equal to the height of the arrow base.
(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.
(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 arrow head width until the value is larger than the arrow base width.
while (arrowHeadWidth <= arrowBaseWidth) {
System.out.println("Enter arrow head width: ");
arrowHeadWidth = scnr.nextInt();
}

Example output for arrowBaseHeight = 5, arrowBaseWidth = 2, and arrowHeadWidth = 4:

Enter arrow base height: 5
Enter arrow base width: 2
Enter arrow head width: 4

**
**
**
**
**
****
***
**
*
Computers and Technology
1 answer:
Maslowich4 years ago
7 0

Answer:

The Java code is given below with appropriate comments for better understanding

Explanation:

<u>// DisplayArrow.java </u>

<u> </u>

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

**

**

**

**

**

****

***

**

*

*/

You might be interested in
Write a program that prompts the user to enter the center and a point on the circle. The program should then output the circle’s
sergij07 [2.7K]

Here is the code in C++.

#include <bits/stdc++.h>

using namespace std;

// function to calculate distance between two points

double distance(int a,int b,int c,int d )

{

 // return the distance between center and point

  return sqrt(pow(c - a, 2) +

               pow(d - b, 2) * 1.0);

}

// driver function

int main()

{

// variables to store coordinates

int x1,y1,x2,y2;

cout<<"Please Enter the center(x y) of the circle: ";

//reading center

cin>>x1>>y1;

cout<<"\nPlease Enter a point(x1 y1) on the circle:";

//reading point

cin>>x2>>y2;

// calling distance() function with 4 parameters

double rad=distance(x1,y1,x2,y2);

// calculating Radius and print

cout<<"Radius of circle is: "<<rad<<endl;

// calculating Diameter and print

cout<<"Diameter of circle is: "<<2*rad<<endl;

// calculating Circumference and print

cout<<"Circumference of circle is: "<<2*3.14*rad<<endl;

// calculating Area and print

cout<<"Area of circle is: "<<3.14*rad*rad<<endl;

return 0;

}

Explanation:

First it will read coordinates of center and point on the circle.The distancebetween center and point on circle is Radius. Call distance() function withfour parameters which are coordinates of center and point. This will return the value of Radius. Diameter is 2 times of Radius.Diameter of a circle is 2*3.14*Radius. and Area of the circle is calculate as 3.14*Radius*Radius. After finding these value print them.

Output:

Please Enter the center(x y) of the circle: 0 0

Please Enter a point(x1 y1) on the circle: 3 4

Radius of circle is: 5

Diameter of circle is: 10

Circumference of circle is: 31.4

Area of circle is: 78.5

4 0
3 years ago
In which of selye's stages in death a possible outcome?
kkurt [141]
D)Exhaustion
Hope this helps
6 0
3 years ago
Which was cited as a reason why Google became so popular?
kupik [55]

Answer:

Google became successful because its founders were well-connected. Google was the world's first and best search engine. Google changed the world by solving an old problem in a new way. Google's other products are now more important to its success than search.

Explanation:

3 0
3 years ago
Which of the following is NOT a common grammar adjustment which is identified by grammar-check software?
Sedbober [7]

Answer:

Shortened versions of phrases Ex:(l ol, s mh, i dk, ect.)

Explanation:

Hope that this helps, if you have any more question please feel free to contact me, hope you have an amazing rest of your day. ;D

7 0
3 years ago
I’m order to protect your passwords, don’t use easy-to-guess information, don’t share your passwords, and NEVER change your pass
Elena L [17]

Answer:

true!

Explanation:

its better to know your password :))

3 0
3 years ago
Other questions:
  • For a typically large organization how many dns servers should you install
    5·1 answer
  • Which of the following menu commands would you select to make a copy of an open file and rename it?
    15·1 answer
  • You can use RWA to demonstrate how to do something special on the web, such as displaying articles found on websites that suppor
    15·1 answer
  • Digital libraries are often available to students and/or employees at colleges, schools, and BLANK institutions.
    15·1 answer
  • When a Python program is reading a file, the data is input as plain ASCII characters in a string. What is the following code doi
    15·1 answer
  • This is not based on homework but I have a question. I am currently using a gtx 960 with a 6 core amd processor. Does anyone kno
    6·1 answer
  • The following is an example of what kind of loop?
    15·2 answers
  • Explain in details how Galen , a physician during the Middle Ages, expanded on Hippocrates' theory of the four humors and explai
    6·1 answer
  • How would I collect a number from the user to use for the radius of a circle?
    13·1 answer
  • Which iteration must have an expression that has a true or false value?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!