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
Wyatt has a database to keep track of his enormous collection of videos. How can Wyatt find the details for the game Lost on Mar
Zinaida [17]

Answer:

edit filter query

Explanation:

plz give branilest hope this helps

5 0
2 years ago
Read 2 more answers
A bag of cookies holds 40 cookies. The calorie information on the bag claims that there are 10 servings in the bag and that a se
laila [671]

Answer:

import java.util.Scanner;

public class ANot {

   public static void main(String[] args) {

   Scanner in = new Scanner (System.in);

       System.out.println("How many cookies did you eat today");

       int numOfCookies = in.nextInt();

       double numCalories = (numOfCookies*300)/4;

       System.out.println("The total number of calories you consumed in "+numOfCookies+" cookies is " +

               " "+numCalories);

   }

}

Explanation:

This code is implemented in Java.

  1. We know from the question that 4 cookies contain 300 calories
  2. Therefore number of calories consumed = (number of cookies eaten*300)/4
  3. To implement this in java we used the scanner class to prompt user for the input
  4. save the input to a variable and write mathematical expression for the number of calories consumed
  5. Then output the result

4 0
3 years ago
Use the ________ method to write text to a web page.
Nastasia [14]
Document.write()

I'm not sure that this is a method, but I think this is right. 
3 0
3 years ago
Based on the description below which website is more appropriate
I am Lyosha [343]

Answer:

D

Explanation:

8 0
3 years ago
Read 2 more answers
Which of the following best describes a server?
Lady_Fox [76]

Answer:

number 4

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Explain the nature of documents that can be suitable for mergin
    12·1 answer
  • When using color in computer-generated presentation aids, you should use?
    10·1 answer
  • __________ offers a mechanism to accomplish four security goals: confidentiality, integrity, authentication, and nonrepudiation.
    9·1 answer
  • The __________ assumption necessary for a linear programming model to be appropriate means that the contribution to the objectiv
    6·1 answer
  • What is an instruction set architecture​
    7·2 answers
  • 2.13 LAB: Branches: Leap Year
    11·1 answer
  • Keeping memos on your checks is important because they
    12·1 answer
  • Can someone send me reference on communication, importance , communication cycle , pros and cos​
    15·1 answer
  • Im coding and need help please answer or comment to help. any skilled coders comment below
    12·1 answer
  • Simon would have regarded with impotent fury the disturbance between the North and the South, as it left his descendants strippe
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!