Advertisement
pproxidevengwess

area figures

Mar 26th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. String input = scanner.nextLine();
  10. double area = 0;
  11. if ("square".equals(input)) {
  12. double side = Double.parseDouble(scanner.nextLine());
  13. area = side*side;
  14. } else if ("ractangle".equals(input)) {
  15. double a = Double.parseDouble(scanner.nextLine());
  16. double b = Double.parseDouble(scanner.nextLine());
  17. area = a * b;
  18. } else if ("circle".equals(input)) {
  19. double r = Double.parseDouble(scanner.nextLine());
  20. area = Math.PI * r * r;
  21. } else if ("triangle".equals(input)) {
  22. double a = Double.parseDouble(scanner.nextLine());
  23. double b = Double.parseDouble(scanner.nextLine());
  24. area = (a*b)/2;
  25. }
  26. System.out.printf("%.3f", area);
  27.  
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement