Advertisement
veronikaaa86

07. Area of Figures

Oct 9th, 2021
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. package conditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P07AreaOfFigures {
  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 l = Double.parseDouble(scanner.nextLine());
  14.  
  15. area = l * l;
  16. } else if (type.equals("rectangle")) {
  17. double w = Double.parseDouble(scanner.nextLine());
  18. double l = Double.parseDouble(scanner.nextLine());
  19.  
  20. area = w * l;
  21. } else if (type.equals("circle")) {
  22. double r = Double.parseDouble(scanner.nextLine());
  23.  
  24. area = Math.PI * r * r;
  25. } else if (type.equals("triangle")){
  26. double l = Double.parseDouble(scanner.nextLine());
  27. double h = Double.parseDouble(scanner.nextLine());
  28.  
  29. area = (l * h) / 2;
  30. }
  31.  
  32. System.out.printf("%.3f", area);
  33.  
  34.  
  35. }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement