borkins

Exam Jan-2016 - 12. Generate Rectangles

May 11th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. /**
  2.  * Project: Exam_101_January_2016 - created by borkins on 2017-05-03.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _12_GenerateRectangles
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.        
  13.         int n = Integer.parseInt(console.nextLine());
  14.         int m = Integer.parseInt(console.nextLine());
  15.    
  16.         int count = 0;
  17.    
  18.         for (int x1 = -n; x1 < n; x1++)
  19.         {
  20.             for (int y1 = -n; y1 < n; y1++)
  21.             {
  22.                 for (int x2 = x1 + 1; x2 <= n; x2++)
  23.                 {
  24.                     for (int y2 = y1 + 1; y2 <= n; y2++)
  25.                     {
  26.                         int a = Math.abs(x2 - x1);
  27.                         int b = Math.abs(y2 - y1);
  28.                    
  29.                         if (a * b >= m) {
  30.                             System.out.printf("(%d, %d) (%d, %d) -> %d%n",
  31.                                               x1, y1, x2, y2, (a * b));
  32.                             count++;
  33.                         }
  34.                     }
  35.                 }
  36.             }
  37.         }
  38.         if (count == 0) System.out.println("No");
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment