Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AreaFigures_06 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //име на фигура -> текст -> квадрат (square), правоъгълник (rectangle), кръг (circle) и триъгълник (triangle)
- String type = scanner.nextLine();
- if(type.equals("square")) {
- //страна на квадрата
- //лице -> страна * страна
- //отпечатаме -> 3 знак
- double a = Double.parseDouble(scanner.nextLine());
- double squareArea = a * a;
- System.out.printf("%.3f", squareArea);
- } else if (type.equals("rectangle")) {
- //страни на правоъгълника -> 2 числа
- //лице -> страна * другата страна
- double sideA = Double.parseDouble(scanner.nextLine());
- double sideB = Double.parseDouble(scanner.nextLine());
- double rectangleArea = sideA * sideB;
- System.out.printf("%.3f", rectangleArea);
- } else if(type.equals("circle")) {
- //радиус
- //лице -> пи * радиус * радиус
- double radius = Double.parseDouble(scanner.nextLine());
- double areaCircle = Math.PI * radius * radius;
- System.out.printf("%.3f", areaCircle);
- } else if(type.equals("triangle")) {
- //страна и височина
- //лице = страна * височината / 2
- double b = Double.parseDouble(scanner.nextLine());
- double hb = Double.parseDouble(scanner.nextLine());
- double triangleArea = b * hb / 2;
- System.out.printf("%.3f", triangleArea);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment