Advertisement
galinyotsev123

ProgBasicsJavaBook3.1SimpleConditions13AreaOfFigures

Jan 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String figure = scanner.nextLine();
  8.  
  9. double cubicMetres = 0;
  10.  
  11. if (figure.equalsIgnoreCase("square")) {
  12. double a = Double.parseDouble(scanner.nextLine());
  13. cubicMetres = a * a;
  14. System.out.printf("%.3f", cubicMetres);
  15. } else if (figure.equalsIgnoreCase("rectangle")) {
  16. double a = Double.parseDouble(scanner.nextLine());
  17. double b = Double.parseDouble(scanner.nextLine());
  18. cubicMetres = a * b;
  19. System.out.printf("%.3f", cubicMetres);
  20. } else if (figure.equalsIgnoreCase("circle")) {
  21. double radius = Double.parseDouble(scanner.nextLine());
  22. cubicMetres = radius * radius * Math.PI;
  23. System.out.printf("%.3f", cubicMetres);
  24. } else if (figure.equalsIgnoreCase("triangle")) {
  25. double a = Double.parseDouble(scanner.nextLine());
  26. double height = Double.parseDouble(scanner.nextLine());
  27. cubicMetres = a * (height / 2);
  28. System.out.printf("%.3f", cubicMetres);
  29. }
  30.  
  31.  
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement