info@meritcampus.com    +91-85006-22255
...

Given the list of points, write a program to count the number of rectangles which can be formed using the given points.

Input (List) Output (int)
`[[1, 1], [3, 3], [1, 3], [3, 1]]` `1`
`[[-4, 3], [-2, 1], [-2, 2], [-2, 5], [-2, 6], [0, 4], [1, 2], [3, 2], [1, 5], [3, 5], [2, 0], [4, 0], [6, 3], [2,-3], [4, -3], [0, 5], [0, 2]` `8`
`[[-2, 1], [0, 0], [2, 1], [4, 1], [4, 3], [2, 2], [1, 4], [3, 5], [1, 2]]` `1`
`[[2, -1], [2, 1], [2, 2], [4, 2], [4, 1], [4, 4], [2, 4], [2, 3], [4, -1], [4, 3]]` `10`
`[[-2, 4], [2, 4], [-2, -2], [4, 7], [2, 7], [-2, 7], [4, 4], [4, -2], [2, -2]]` `9`

``` class CountRectangles {    public static void main(String s[])    {        List points = new ArrayList();        points.add(new Point(1, 1));        points.add(new Point(2, 2));        points.add(new Point(2, 1));        points.add(new Point(3, 3));        points.add(new Point(2, 0));        points.add(new Point(3, 1));        points.add(new Point(6, 3));        points.add(new Point(4, 1));        points.add(new Point(4, 2));        System.out.println("The number of rectangles formed by the given points are : " + countRectangles(points));    } public static int countRectangles(List<Point> list) { //Write the code here to count the rectangles which can be formed by the given points } //If required, write the additional methods here } class Point { int x; int y; Point(int x, int y) { this.x = x; this.y = y; } @Override public String toString() { return "[" + x + ", " + y + "]"; } } ```

Topic: Java ArrayList

0
Wrong
Score more than 2 points