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

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

Input (List) Output (int)
`[[1, 1], [2, 1], [1, 2], [2, 2]]` `4`
`[[1, 1], [2, 1], [1, 2], [2, 2], [1, 3]]` `9`
`[[2, 0], [5, 1], [5, 2], [4, 2], [2, 3], [2, 1], [1, 1], [1, 2], [1, 4]]` `80`
`[[0, 0], [0, 3], [1, 1], [1, 3], [2, 0], [3, 3], [2, 4], [1, 5]]` `52`
`[[0, 1], [2, -1], [0, 0], [1, 4], [2, 2], [3, 1], [4, 3]]` `33`
` [[0, 1], [0, -1], [1, -1], [2, 0], [1, 2], [3, 3]]` `20`
` [[-3, 1], [-2, 2], [-1, 1], [-2, 1], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5]]` `69`

``` import java.util.*; class CountTriangles {     public static void main(String s[])    {        List<Point> points = new ArrayList<Point>();        points.add(new Point(0, 0));        points.add(new Point(2, 0));        points.add(new Point(5, 1));        points.add(new Point(5, 2));        points.add(new Point(4, 2));        points.add(new Point(2, 3));        points.add(new Point(2, 1));        points.add(new Point(1, 1));        points.add(new Point(1, 2));        points.add(new Point(1, 4));        System.out.println("The number of the triangles which can be formed by the given points are " + countTriangles(points));    }     public static int countTriangles(List<Point> list) { ```
```     }      ```
``` } 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