Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
0
Indexable
Never
package ConditionalStatementsLab;

import java.util.Scanner;

public class AreaOfFigures_07 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String name = scanner.nextLine();

        if (name.equals("square")){
            double a = Double.parseDouble(scanner.nextLine());
            double result = a * a;
            System.out.printf("%.3f", result);
        } else if (name.equals("rectangle")) {
            double a = Double.parseDouble(scanner.nextLine());
            double b = Double.parseDouble(scanner.nextLine());
            double result = a * b;
            System.out.printf("%.3f", result);
        } else if (name.equals("circle")) {
            double a = Double.parseDouble(scanner.nextLine());
            double result = Math.PI * (a * a);
            System.out.printf("%.3f", result);
        } else if (name.equals("triangle")) {
            double a = Double.parseDouble(scanner.nextLine());
            double b = Double.parseDouble(scanner.nextLine());
            double result = (a * b) / 2 ;
            System.out.printf("%.3f", result);
        }


    }
}