Guest User

Rectangles

a guest
Nov 3rd, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class GenerateRectangles {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.         int m = Integer.parseInt(scanner.nextLine());
  10.         int count = 0;
  11.         boolean noPrint = false;
  12.  
  13.         for (int left = -n; left <= n; left++) {
  14.             for (int top = -n; top <= n; top++) {
  15.                 for (int right = left + 1; right <= n; right++) {
  16.                     for (int bottom = top + 1; bottom <= n; bottom++) {
  17.                         int width = right - left;
  18.                         int height = bottom - top;
  19.                         int area = width * height;
  20.  
  21.                         if (area >= m) {
  22.                             System.out.printf("(%d, %d) (%d, %d) -> %d%n", left, top, right, bottom, area);
  23.                             noPrint = true;
  24.                         }
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.         if (!noPrint) {
  30.             System.out.println("No");
  31.         }
  32.  
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment