Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package conditionalStatements;
- import java.util.Scanner;
- public class P07AreaOfFigures {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String type = scanner.nextLine();
- //квадрат (square), правоъгълник (rectangle), кръг (circle) и триъгълник (triangle)
- double area = 0;
- if (type.equals("square")) {
- double a = Double.parseDouble(scanner.nextLine());
- area = a * a;
- } else if (type.equals("rectangle")) {
- double a = Double.parseDouble(scanner.nextLine());
- double b = Double.parseDouble(scanner.nextLine());
- area = a * b;
- } else if (type.equals("circle")) {
- double r = Double.parseDouble(scanner.nextLine());
- area = Math.PI * r * r;
- } else if (type.equals("triangle")) {
- double a = Double.parseDouble(scanner.nextLine());
- double h = Double.parseDouble(scanner.nextLine());
- area = (a * h) / 2;
- }
- System.out.printf("%.3f", area);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement