Rectangle rect = new Rectangle(0, 0, 0, 0); if(rect.isEmpty()) { System.out.println("The rectangle is empty"); }
Rectangle rect = new Rectangle(-10, -10, 20, 20); if(!rect.isEmpty()) { System.out.println("The rectangle is not empty"); }Output: The rectangle is not empty This code creates a rectangle with dimensions of 20 pixels in width and height, starting from -10 coordinates of both x and y axis. It checks if the rectangle is not empty using the negation operator (!) and prints the message "The rectangle is not empty". The java.awt.Rectangle class is part of the java.awt package library, which provides classes for creating and handling graphical user interfaces (GUIs) in Java.