Advertisement
desislava_topuzakova

07. 2D Rectangle Area

Apr 22nd, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Rectangle2D {
  4.     public static void main(String[] agrs) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         double x1 = Double.parseDouble(scan.nextLine());
  8.         double y1 = Double.parseDouble(scan.nextLine());
  9.         double x2 = Double.parseDouble(scan.nextLine());
  10.         double y2 = Double.parseDouble(scan.nextLine());
  11.  
  12.         double a = Math.max(x1, x2) - Math.min(x1, x2);
  13.         double b = Math.max(y2, y1) - Math.min(y1, y2);
  14.  
  15.         double area = a * b;
  16.         double perimeter = 2 * (a + b);
  17.  
  18.         System.out.println(area);
  19.         System.out.println(perimeter);
  20.  
  21.  
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement