Advertisement
veronikaaa86

07. Area of Figures

Mar 5th, 2022
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. package conditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class AreaOfFigures {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String type = scanner.nextLine();
  10.  
  11. double area = 0;
  12. if (type.equals("square")) {
  13. double side = Double.parseDouble(scanner.nextLine());
  14.  
  15. area = side * side;
  16.  
  17. } else if (type.equals("rectangle")) {
  18. double sideA = Double.parseDouble(scanner.nextLine());
  19. double sideB = Double.parseDouble(scanner.nextLine());
  20.  
  21. area = sideA * sideB;
  22.  
  23. } else if (type.equals("circle")) {
  24. double radius = Double.parseDouble(scanner.nextLine());
  25.  
  26. area = Math.PI * radius * radius;
  27.  
  28. } else if (type.equals("triangle")) {
  29. double side = Double.parseDouble(scanner.nextLine());
  30. double height = Double.parseDouble(scanner.nextLine());
  31.  
  32. area = side * height / 2;
  33. }
  34.  
  35. System.out.printf("%.3f", area);
  36. }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement