Rectangle with Maximum Area using Java Pair Last Updated : 22 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Try it on GfG Practice Given an array of pairs containing length and breadth of rectangles. The task is to find the maximum area of the rectangle. Examples: Input: (1, 2), (3, 5), (1, 1), (4, 2) Output: 15 Input: (3, 5), (5, 5), (9, 10) Output: 90Recommended PracticeMaximum Area RectangleTry It! Approach: Use user defined Pair class to store Breadth and Height of rectangles.Make an array of this class.Now, traverse the array and find the area each time. Also, keep track of maximum area.Return the maximum area of rectangle. Java // Java code to find maximum Area import java.io.*; import java.util.*; // Pair class class Rectangle { // length and int length; int breadth; // Rectangle Constructor public Rectangle(int x, int y) { this.length = x; this.breadth = y; } } // Class Area to calculate Area of rectangles class Area { // Function to calculate area static int calculate_Area(Rectangle arr[]) { int max_Area = Integer.MIN_VALUE; // loop to iterate through all rectangles // and keep track of max area for (int i = 0; i < arr.length; i++) { int temp_area = arr[i].length * arr[i].breadth; if (temp_area > max_Area) { max_Area = temp_area; } } return max_Area; } } // Driver class with main function class GFG { // Driver code public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Creating an array of Pair Rectangle arr[] = new Rectangle[3]; int x = 10, y = 20; arr[0] = new Rectangle(x, y); x = 5; y = 25; arr[1] = new Rectangle(x, y); x = 15; y = 10; arr[1] = new Rectangle(x, y); x = 12; y = 12; arr[2] = new Rectangle(x, y); Area obj = new Area(); System.out.println(obj.calculate_Area(arr)); } } Output:200 Time complexity: O(n) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Rectangle with Maximum Area using Java Pair B barykrg Follow Improve Article Tags : Java Java Programs DSA Arrays area-volume-programs +1 More Practice Tags : ArraysJava Similar Reads Java Program for Number of pairs with maximum sum Write a java program for a given array arr[], count number of pairs arr[i], arr[j] such that arr[i] + arr[j] is maximum and i < j.Example: Input : arr[] = {1, 1, 1, 2, 2, 2}Output: 3Explanation: The maximum possible pair sum where i<j is 4, which is given by 3 pairs, so the answer is 3 the pai 4 min read JavaFX | Rectangle and Rounded Rectangle with examples Rectangle class is a part of JavaFX. Rectangle class creates a rectangle with specified width and height and position. By default Rectangle has sharp corners but the edges can be rounded by applying a arc height and width. Constructor : Rectangle(): creates a empty instance of rectangleRectangle(dou 4 min read Java Program to Find Area of Rectangle Using Method Overloading A rectangle is a simple flat figure in a plane. It has four sides and four right-angles. In a rectangle all four sides are not of equal length like a square, sides opposite to each other have equal length and both the diagonals of the rectangle have equal length. Method overloading allows different 2 min read Java Program to Find the Perimeter of a Rectangle A Rectangle is a quadrilateral with four right angles (90°). In a rectangle, the opposite sides are equal. A rectangle with all four sides equal is called a Square. A rectangle can also be called as right angled parallelogram. Rectangle In the above rectangle, the sides A and C are equal and B and D 2 min read Java Program to Find the Area of Rhombus A rhombus is a quadrilateral whose four sides all have the same length and a rhombus is also called an equilateral quadrilateral. The formula for finding the area of a rhombus is as follows: (product of the lengths of the diagonals)/2 Example: Input : p = 2, q = 3 Output: 3Input : p = 4, q = 5 Outpu 1 min read Like