import java.awt.Rectangle; public class Example1 { public static void main(String[] args) { Rectangle rect = new Rectangle(5, 10, 20, 15); double maxY = rect.getMaxY(); System.out.println("Maximum Y-coordinate of the rectangle is : " + maxY); } }
import java.awt.Rectangle; public class Example2 { public static void main(String[] args) { Rectangle rect1 = new Rectangle(10, 20, 30, 25); Rectangle rect2 = new Rectangle(15, 35, 25, 20); Rectangle rect3 = rect1.union(rect2); double maxY = rect3.getMaxY(); System.out.println("Maximum Y-coordinate of the union of rect1 and rect2 is : " + maxY); } }In this example, we create two Rectangle objects rect1 and rect2 with different locations and sizes. Then, we call the union() method on rect1 with rect2 as an argument to get the union of both rectangles. After that, we call the getMaxY() method on the union of the two rectangles to get the maximum Y-coordinate. Finally, we print the value of maxY on the console. Package library: java.awt