Advertisement
Guest User

Untitled

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