import java.awt.Rectangle; public class RectangleExample { public static void main(String[] args) { Rectangle rect = new Rectangle(10, 20, 30, 40); int height = rect.getHeight(); System.out.println("The height of the rectangle is: " + height); } }
import java.awt.Rectangle; public class RectangleExample { public static void main(String[] args) { Rectangle rect1 = new Rectangle(10, 20, 30, 40); Rectangle rect2 = new Rectangle(50, 60, 70, 80); if(rect1.getHeight() > rect2.getHeight()) { System.out.println("Rectangle 1 is taller than Rectangle 2"); } else { System.out.println("Rectangle 2 is taller than Rectangle 1"); } } }This example creates two Rectangle objects with different coordinates and sizes. The getHeight method is called on both objects and the heights are compared in an if statement to determine which rectangle is taller. The package library used is java.awt.