Advertisement
yovkovbpfps

areaOfFigures

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