Answer to Question #175874 in Java | JSP | JSF for Marc Quining

Question #175874

Write a program that computes the area of a circular region (the shaded area in the diagram), given the radii of the inner and the outer circles, ri and ro, respectively.



1
Expert's answer
2021-03-26T13:05:04-0400
import java.util.Scanner;


public class Q175874 {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// Create Scanner object
		Scanner keyboard = new Scanner(System.in);
		try {
			// Get the radius of the inner circle from the user
			System.out.print("Enter the radius of the inner circle: ");
			double ri = keyboard.nextDouble();
			double ro=-1;
			while(ro<ri) {
				//Get the radius of the outer circle from the user
				System.out.print("Enter the radius of the outer circle: ");
				ro = keyboard.nextDouble();
			}
			//Calculate the area the inner circle
			double areaInnerCircle=Math.PI*ri*ri;
			//Calculate the area the outer circle
			double areaOuterCircle=Math.PI*ro*ro;
			double areaCircularRegion=areaOuterCircle-areaInnerCircle;
			
			System.out.println("The area of a circular region: "+areaCircularRegion);
			
		} catch (Exception e) {
			// Display error message
			System.out.println(e.getMessage());
		}
		// close Scanner
		keyboard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog