SHARE
TWEET

Untitled

a guest Sep 19th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top