Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class Areas {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- DecimalFormat df = new DecimalFormat("#.###");
- String type = scanner.nextLine();
- if (type.equals("square")){
- double side = Double.parseDouble(scanner.nextLine());
- double area = side * side;
- System.out.printf(df.format(area));
- }else if (type.equals("rectangle")){
- double sideA = Double.parseDouble(scanner.nextLine());
- double sideB = Double.parseDouble(scanner.nextLine());
- double area = (sideA * sideB);
- System.out.printf(df.format(area));
- }else if (type.equals("circle")){
- double radius = Double.parseDouble(scanner.nextLine());
- double area = Math.PI * radius * radius;
- System.out.printf(df.format(area));
- }else if (type.equals("triangle")){
- double sideB = Double.parseDouble(scanner.nextLine());
- double h = Double.parseDouble(scanner.nextLine());
- double area = (sideB * h) / 2;
- System.out.printf("%.3f",area);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement