import java.awt.Rectangle; public class Example { public static void main(String[] args) { Rectangle rect = new Rectangle(10, 10, 20, 20); double maxX = rect.getMaxX(); System.out.println("Max X-coordinate: " + maxX); } }
Max X-coordinate: 30.0
import java.awt.Rectangle; import java.util.Random; public class Example { public static void main(String[] args) { Random rand = new Random(); Rectangle[] rects = new Rectangle[5]; for (int i = 0; i < rects.length; i++) { int x = rand.nextInt(50); int y = rand.nextInt(50); int w = rand.nextInt(20) + 10; int h = rand.nextInt(20) + 10; rects[i] = new Rectangle(x, y, w, h); } double maxX = rects[0].getMaxX(); for (int i = 1; i < rects.length; i++) { if (rects[i].getMaxX() > maxX) { maxX = rects[i].getMaxX(); } } System.out.println("Max X-coordinate: " + maxX); } }
Max X-coordinate: 62.0Package/library: java.awt