Advertisement
desislava_topuzakova

03.2D Rectangle Area

Feb 9th, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class RectangleArea2D_03 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double x1 = Double.parseDouble(scanner.nextLine());
  8.         double y1 = Double.parseDouble(scanner.nextLine());
  9.         double x2 = Double.parseDouble(scanner.nextLine());
  10.         double y2 = Double.parseDouble(scanner.nextLine());
  11.  
  12.         double width = Math.abs(y1 - y2);
  13.         double length = Math.abs(x1 - x2);
  14.         double area = width * length;
  15.         double perimeter = 2 * (width + length);
  16.  
  17.         System.out.printf("%.2f%n", area);
  18.         System.out.printf("%.2f", perimeter);
  19.  
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement