Question

Palayiapin Jlyies LUILITY Task02: An orange square is inscribed inside a circle as shown in the diagram below. Write an inter

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.InputMismatchException;
import java.util.Scanner;

public class GreenArea {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        try {
            System.out.print("Enter the area of the square [sq cm]: ");
            double squareArea = in.nextDouble();
            double radius = Math.sqrt(squareArea / 2);
            double circleArea = Math.PI * radius * radius;
            double greenArea = circleArea - squareArea;
            System.out.printf("Green area = %.2f square cm\n", greenArea);
        } catch (InputMismatchException e) {
            System.out.println("Error: Invalid input");
        } catch (Exception e) {
            System.out.println("Error: Invalid input");
        }
    }
}

Enter the area of the square [sq cm]: 26.75 Green area = 15.27 square cm Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
Palayiapin Jlyies LUILITY Task02: An orange square is inscribed inside a circle as shown in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4...

    23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same...

  • 23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this...

    23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same as what you had for your chapter 13 labs). The following is an example of...

  • In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk,...

    In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containers. The shipping charges depend on the amount of the liquid in the container. (For simplicity, you may assume that the container is filled to the top.) They also provide the option to paint the outside of the container for a reasonable amount. Write a program that does the following: Prompts the user to input the dimensions (in feet)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT