SHARE
TWEET

Untitled

a guest Sep 18th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top