Advertisement
SUni2020

GenerateRectangles

Mar 28th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GenerateRectangles {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = Integer.parseInt(scanner.nextLine());
  7. int m = Integer.parseInt(scanner.nextLine());
  8. int count = 0;
  9.  
  10. for (int left = -n; left < n; left++) {
  11. for (int top = -n; top < n; top++) {
  12. for (int right = left + 1; right <= n; right++) {
  13. for (int bottom = top + 1; bottom <= n; bottom++) {
  14. int area =
  15. Math.abs(right - left) * Math.abs(bottom - top);
  16. if (area >= m) {
  17. System.out.printf("(%d, %d) (%d, %d) -> %d%n",
  18. 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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement