Solved CountTriangles in java