Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main
- {
- public static void main(String[] args)
- {
- Scanner console = new Scanner(System.in);
- int n = Integer.parseInt(console.nextLine());
- int m = Integer.parseInt(console.nextLine());
- int count = 0;
- for (int x1 = -n; x1 < n; x1++)
- {
- for (int y1 = -n; y1 < n; y1++)
- {
- for (int x2 = x1 + 1; x2 <= n; x2++)
- {
- for (int y2 = y1 + 1; y2 <= n; y2++)
- {
- int a = Math.abs(x2 - x1);
- int b = Math.abs(y2 - y1);
- if (a * b >= m) {
- System.out.printf("(%d, %d) (%d, %d) -> %d%n", x1, y1, x2, y2, (a * b));
- count++;
- // Drawing the rectangles on the coordinate system
- drawRectangle(x1, y1, x2, y2, n);
- }
- }
- }
- }
- }
- if (count == 0) System.out.println("No");
- }
- public static void drawRectangle(int x1, int y1, int x2, int y2, int gridSize)
- {
- int size = gridSize + 3;
- System.out.print("\n ");
- for (int col = -size; col <= size; col++)
- {
- System.out.printf(" %2d", col);
- }
- System.out.println();
- for (int row = -size; row <= size; row++)
- {
- System.out.printf("%2d", row);
- for (int col = -size; col <= size; col++)
- {
- System.out.print(((col == x1 || col == x2) &&
- (row == y1 || row == y2)) ? " * " : " | ");
- }
- System.out.println();
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment