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]
4 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]4 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
What is the significance of the following terms A A L U control unit in the CPU​
WARRIOR [948]

Answer:

Explanation:

The function of ALU is to perform arithmetic operations(add,subtract, multiply,division) as well as logical operations(compare values).

The function of CU is to control and coordinate the activities of the computer.

8 0
3 years ago
Human services organizations seek to make changes and help people in need to improve their .
bixtya [17]

Answer:

quality of life

Explanation:

7 0
3 years ago
The Zoom slider will allow users to _____.
NeX [460]
The Zoom slider will allow users to change the way the document appears on the screen
3 0
3 years ago
Read 2 more answers
You have defined a scope on your DHCP server with the start address 172.16.1.1, end address 172.16.1.200, and prefix length 16.
Andre45 [30]

Answer:

B

Explanation:

prefix 16 got 255.555.0.0 subnet mask & 65,536 total host. so in your case it ill take 172.16.0.0 - 172.16.255.255 / subnet and your scope ill take the 172.16.1.1 - 172.16.1.200 . for the next subnet is 172.17.0.0 - 172.17.255.255 and same thing as your scope you ill take 172.17.1.1 - 173.17.1.200 . keep learning bro :)

7 0
3 years ago
What is the extension of a BASIC256 program file?​
algol13

Answer:

The extension of a BASIC-256 program file is kbs

4 0
3 years ago
Other questions:
  • Which of the following best describes why Earth’s atmosphere can support life on Earth?
    14·1 answer
  • A 5.5 g sample of a substance contains only carbon and oxygen. Carbon makes up 35% of the mass of the substance. The rest is mad
    8·1 answer
  • Create a file with a 20 lines of text and name it "lines.txt". Write a program to read this a file "lines.txt" and write the tex
    12·1 answer
  • List two ways to exit the room properties dialog box, saving changes to the room
    12·1 answer
  • What need did anti lock brakes address?
    10·1 answer
  • Motivational appeals refer to
    15·1 answer
  • Houston want to have a quick conversion with his friend about an upcoming school activity. which type of website would be most u
    12·2 answers
  • In MMF2, what does the * symbol mean?
    5·1 answer
  • You are working from home and want to discuss a controversial topic. It is important you see the facial expressions of your cowo
    6·2 answers
  • Call of duty vanguard, war zone , fornite, gta what’s your favorite
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!