Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AreaOfFigures {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String geometricShape = scanner.nextLine().toLowerCase();
- switch (geometricShape) {
- case "square":
- double side = Double.parseDouble(scanner.nextLine());
- System.out.printf("%.3f%n", (side * side));
- break;
- case "rectangle":
- double length = Double.parseDouble(scanner.nextLine());
- double width = Double.parseDouble(scanner.nextLine());
- System.out.printf("%.3f%n", (length * width));
- break;
- case "circle":
- double radius = Double.parseDouble(scanner.nextLine());
- System.out.printf("%.3f%n", (Math.PI * radius * radius));
- break;
- case "triangle":
- double base = Double.parseDouble(scanner.nextLine());
- double hight = Double.parseDouble(scanner.nextLine());
- System.out.printf("%.3f%n", (base * hight / 2));
- break;
- default:
- System.out.println("Unknown geometric shape.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement