Advertisement
Guest User

Untitled

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