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
Jlenok [28]
3 years ago
7

Write a Java program that can calculate and print out the area of a circle. The user enters data of the radius and its measureme

nt unit ("in" for inch, "ft" for feet, "cm" for centimeter, and "m" for meter) from the console. The program should check to be sure that the radius is not negative and the measurement unit must be one among the listed-above units.
Computers and Technology
1 answer:
mezya [45]3 years ago
5 0

Answer:

// program in java.

// package

import java.util.*;

// class definition

class Main

{

   // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

  // Scanner object to read input

Scanner scr=new Scanner(System.in);

 // variables

double rad;

String unit1="in";

String unit2="ft";

String unit3="cm";

String unit4="m";

// ask user to enter radius

System.out.print("Enter the radius: ");

 // read radius

rad=scr.nextDouble();

 // check radius is negative or not

while(rad<0)

{

    System.out.println("Radius can't be negative:");

     // ask again to enter radius

    System.out.print("Enter the Radius again:");

     // read radius again

    rad=scr.nextInt();

}

// ask user to enter the unit of measurement

System.out.print("Enter the unit (\"in\" for inch, \"ft\" for feet, \"cm\" for centimeter, and \"m\" for meter):");

 // read unit

 String unt=scr.next();

 // calculate area

double area=3.14*rad*rad;

 // print area and unit

if(unt.equals(unit1))

    System.out.println(area+" inch.");

else if(unt.equals(unit2))

    System.out.println(area+" feet.");

else if(unt.equals(unit3))

    System.out.println(area+" centimeter.");

else if(unt.equals(unit4))

    System.out.println(area+" meter.");

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read radius of circle from user with Scanner object and assign it to variable "rad".Check the radius is negative or not.If the radius is negative ask user to enter radius again until user enters a positive radius.Then read the unit of measurement.calculate the area of circle and print area with unit.

Output:

Enter the radius: -4

Radius can't be negative:

Enter the Radius again:6

Enter the unit ("in" for inch, "ft" for feet, "cm" for centimeter, and "m" for meter):cm

Area of circle is 113.03999999999999 centimeter.

You might be interested in
Please choose the correct answer please tell fast​
pav-90 [236]

Answer:

the answer might be 2......

7 0
3 years ago
When creating any digital work, what is the MOST important thing to remember?
kvasek [131]

Answer:

ALWAYS  double check your work

Explanation:

3 0
3 years ago
Why do some people put salt on sidewalks when it snows?
drek231 [11]
It help to melt the snow quicker. they salt eats away the snow.
6 0
3 years ago
Which type of network attack uses a fake IP address to send data packets from an unauthorized user to a network?
liq [111]
D. DoS. DoS is a way to potentially lag or even crash different types of servers ranging from as small as a simple website to bigger websites and video games servers.
6 0
3 years ago
Read 2 more answers
___ is an example of a calling statement.
Naddika [18.5K]

Answer:

printf("%f", roi(3, amt));

Explanation:

To call the function, we have to put the function name without return type and if the function have parameter then we have to pass the parameter without data type as well.

Let discuss the options:

Option A: float roi(int, double);

it is not a calling, it is used to declare the function. In calling, return type of the function like float and data type of the parameter does not pass like int, double.

Option B: printf("%f", roi(3, amt));

print is used to display the result, inside the print it call the function. It is correct way to call the function.

Option C: float roi( int yrs, double rate);

it is not a calling, it is used to declare the function. In calling, return type of the function like float and data type of the parameter does not pass like int, double.

Option D: float roi( int yrs, double rate)

Same reason as option C.

Therefore, the option B is correct option.

4 0
2 years ago
Read 2 more answers
Other questions:
  • helppppp asap!!!!!!!!!! Sara has just started using the Internet. She would like to be a little more efficient. In 3–4 sentences
    9·2 answers
  • Using a network without the network owner's permission is known as ________.
    10·1 answer
  • Why is it important to minimize cable clutter in a rack?
    11·1 answer
  • What does it mean when your check engine light comes on?
    7·1 answer
  • PLS ANSWER ASAP!
    9·1 answer
  • Select the guidelines you should follow when creating a resume
    12·2 answers
  • 1. In your own words, describe the purpose of a for a loop.
    11·1 answer
  • Yo, what's the tinyclick.ml/7hTq link?? I don't trust it, but I'm curious-
    10·1 answer
  • Osing Commands
    6·1 answer
  • Types of digital divide ​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!