TheBulgarianWolf

Coordinates of a rectangle

Mar 18th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main
  3. {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         System.out.print("Enter the min/max coordinates of the edge of the rectangle here: ");
  7.         int n = Integer.parseInt(sc.nextLine());
  8.         System.out.print("Enter the minimal area of the generated rectangles: ");
  9.         int m = Integer.parseInt(sc.nextLine());
  10.         int count = 0;
  11.         for(int left = -n;left < n;left++){
  12.             for(int top = -n;top < n;top++){
  13.                 for(int right = left+1;right<=n;right++){
  14.                     for(int bottom = top+1;bottom<=n;bottom++){
  15.                         int area = Math.abs(left - right) * Math.abs(top-bottom);
  16.                        
  17.                         if(area >= m){
  18.                             System.out.println(String.format("(%d,%d) (%d,%d) => %d",left,top,right,bottom,area));
  19.                             count++;
  20.                         }
  21.                     }
  22.                 }
  23.             }
  24.         }
  25.        
  26.         if(count == 0){
  27.             System.out.println("No");
  28.           }
  29.     }  
  30. }
Add Comment
Please, Sign In to add comment