ralitsa_d

Area

Jan 18th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Area {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. String shape = scan.nextLine();
  8.  
  9. double side, height = 0;
  10.  
  11. side = Double.parseDouble(scan.nextLine());
  12.  
  13. if(shape.equals("rectangle") || shape.equals("triangle")){
  14. height = Double.parseDouble(scan.nextLine());
  15. }
  16.  
  17. double area = 0;
  18.  
  19. if (shape.equals("square")){
  20. area = side * side;
  21. }
  22. else if(shape.equals("circle")){
  23. area = Math.PI * Math.pow(side, 2);
  24. }
  25. else if(shape.equals("rectangle")){
  26. area = side * height;
  27. }
  28. else{
  29. area = side * height / 2;
  30. }
  31.  
  32. System.out.println(area);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment