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

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

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

``` class CountSquares {    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(5, 2));        System.out.println("The number of squares formed by the given points are : " + countSquares(points));    } public static int countSquares(List<Point> list) { //Write the code here to count the squares which can be formed by the given points } //If required, write any 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