codeparrot/xlcost-text-to-code huggingface dataset:
Find area of parallelogram if vectors of two adjacent sides are given | Java code to calculate area of parallelogram if vectors of 2 adjacent sides are given ; Function to calculate area of parallelogram ; Driver code
public class GFG { static float area ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 ) { float area = ( float ) Math . sqrt ( Math . pow ( ( y1 * z2 - y2 * z1 ) , 2 ) + Math . pow ( ( x1 * z2 - x2 * z1 ) , 2 ) + Math . pow ( ( x1 * y2 - x2 * y1 ) , 2 ) ) ; return area ; } public static void main ( String args [ ] ) { float x1 = 3 ; float y1 = 1 ; float z1 = - 2 ; float x2 = 1 ; float y2 = - 3 ; float z2 = 4 ; float a = area ( x1 , y1 , z1 , x2 , y2 , z2 ) ; System . out . println ( " Area ▁ = ▁ " + a ) ; } }
Maximum possible intersection by moving centers of line segments | Java implementation of above approach ; Function to print the maximum intersection ; Case 1 ; Case 2 ; Case 3 ; Driver Code
import java . util . * ; class GFG { static int max_intersection ( int center [ ] , int length , int k ) { Arrays . sort ( center ) ; if ( center [ 2 ] - center [ 0 ] >= 2 * k + length ) { return 0 ; } else if ( center [ 2 ] - center [ 0 ] >= 2 * k ) { return ( 2 * k - ( center [ 2 ] - center [ 0 ] - length ) ) ; } else return length ; } public static void main ( String args [ ] ) { int center [ ] = { 1 , 2 , 3 } ; int L = 1 ; int K = 1 ; System . out . println ( max_intersection ( center , L , K ) ) ; } }
Haversine formula to find distance between two points on a sphere | Java program for the haversine formula ; distance between latitudes and longitudes ; convert to radians ; apply formulae ; Driver Code
public class Haversine { static double haversine ( double lat1 , double lon1 , double lat2 , double lon2 ) { double dLat = Math . toRadians ( lat2 - lat1 ) ; double dLon = Math . toRadians ( lon2 - lon1 ) ; lat1 = Math . toRadians ( lat1 ) ; lat2 = Math . toRadians ( lat2 ) ; double a = Math . pow ( Math . sin ( dLat / 2 ) , 2 ) + Math . pow ( Math . sin ( dLon / 2 ) , 2 ) * Math . cos ( lat1 ) * Math . cos ( lat2 ) ; double rad = 6371 ; double c = 2 * Math . asin ( Math . sqrt ( a ) ) ; return rad * c ; } public static void main ( String [ ] args ) { double lat1 = 51.5007 ; double lon1 = 0.1246 ; double lat2 = 40.6892 ; double lon2 = 74.0445 ; System . out . println ( haversine ( lat1 , lon1 , lat2 , lon2 ) + " ▁ K . M . " ) ; } }
Pentatope number | Java Program to find the nth Pentatope Number ; Function that returns nth pentatope number ; Driver Code ; For 5 th PentaTope Number ; For 11 th PentaTope Number
import java . io . * ; class GFG { static int pentatopeNum ( int n ) { return ( n * ( n + 1 ) * ( n + 2 ) * ( n + 3 ) ) / 24 ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( pentatopeNum ( n ) ) ; n = 11 ; System . out . println ( pentatopeNum ( n ) ) ; } }
Heptagonal number | Java program to find the nth Heptagonal number ; Function to return Nth Heptagonal number ; Driver Code
import java . io . * ; class GFG { static int heptagonalNumber ( int n ) { return ( ( 5 * n * n ) - ( 3 * n ) ) / 2 ; } public static void main ( String [ ] args ) { int n = 2 ; System . out . println ( heptagonalNumber ( n ) ) ; n = 15 ; System . out . println ( heptagonalNumber ( n ) ) ; } }
Icosidigonal number | Java program to find nth Icosidigonal number ; Function to calculate Icosidigonal number ; Formula for finding nth Icosidigonal number ; Driver Code
import java . io . * ; class GFG { static int icosidigonal_num ( int n ) { return ( 20 * n * n - 18 * n ) / 2 ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( n + " th ▁ Icosidigonal ▁ number ▁ : " ) ; System . out . println ( icosidigonal_num ( n ) ) ; n = 8 ; System . out . print ( n + " th ▁ Icosidigonal ▁ number ▁ : " ) ; System . out . println ( icosidigonal_num ( n ) ) ; } }
Hypercube Graph | Java program to find vertices in a hypercube graph of order n ; Function to find power of 2 ; Driver program
class GfG { static int power ( int n ) { if ( n == 1 ) return 2 ; return 2 * power ( n - 1 ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( power ( n ) ) ; } }
Reflection of a point at 180 degree rotation of another point | Java Program to find the 180 degree reflection of one point around another point . ; Driver code
class GFG { static void findPoint ( int x1 , int y1 , int x2 , int y2 ) { System . out . println ( " ( " + ( int ) ( 2 * x2 - x1 ) + " , " + ( int ) ( 2 * y2 - y1 ) + " ▁ ) " ) ; } public static void main ( String args [ ] ) { int x1 = 0 , y1 = 0 , x2 = 1 , y2 = 1 ; findPoint ( x1 , y1 , x2 , y2 ) ; } }
Program to check if the points are parallel to X axis or Y axis | Java program to illustrate . . To check for parallel To X and Y Axis ; To check for parallel line ; checking for parallel to X and Y axis condition ; To display the output ; Driver 's Code
import java . io . * ; import java . util . * ; class GFG { static void parallel ( int a [ ] [ ] ) { boolean x = true , y = true ; for ( int i = 0 ; i < a . length - 1 ; i ++ ) { if ( a [ i ] [ 0 ] != a [ i + 1 ] [ 0 ] ) x = false ; if ( a [ i ] [ 1 ] != a [ i + 1 ] [ 1 ] ) y = false ; } if ( x ) System . out . println ( " Parallel ▁ to ▁ Y ▁ Axis " ) ; else if ( y ) System . out . println ( " Parallel ▁ to ▁ X ▁ Axis " ) ; else System . out . println ( " Not ▁ parallel ▁ to ▁ X " + " ▁ and ▁ Y ▁ axis " ) ; } public static void main ( String [ ] args ) { int a [ ] [ ] = { { 1 , 2 } , { 1 , 4 } , { 1 , 6 } , { 1 , 0 } } ; parallel ( a ) ; } }
Triangular Matchstick Number | Java program to find X - th triangular matchstick number ; Driver code
public class TriangularPyramidNumber { public static int numberOfSticks ( int x ) { return ( 3 * x * ( x + 1 ) ) / 2 ; } public static void main ( String [ ] args ) { System . out . println ( numberOfSticks ( 7 ) ) ; } }
Total area of two overlapping rectangles | Java program to find total area of two overlapping Rectangles ; Returns Total Area of two overlap rectangles ; Area of 1 st Rectangle ; Area of 2 nd Rectangle ; Length of intersecting part i . e start from max ( l1 . x , l2 . x ) of x - coordinate and end at min ( r1 . x , r2 . x ) x - coordinate by subtracting start from end we get required lengths ; Driver Code ; Function Call
class GFG { static class Point { int x , y ; public Point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static int overlappingArea ( Point l1 , Point r1 , Point l2 , Point r2 ) { int area1 = Math . abs ( l1 . x - r1 . x ) * Math . abs ( l1 . y - r1 . y ) ; int area2 = Math . abs ( l2 . x - r2 . x ) * Math . abs ( l2 . y - r2 . y ) ; int x_dist = ( Math . min ( r1 . x , r2 . x ) - Math . max ( l1 . x , l2 . x ) ; int y_dist = ( Math . min ( r1 . y , r2 . y ) - Math . max ( l1 . y , l2 . y ) ; int areaI = 0 ; if ( x_dist > 0 && y_dist > 0 ) { areaI = x_dist * y_dist ; } return ( area1 + area2 - areaI ) ; } public static void main ( String [ ] args ) { Point l1 = new Point ( 2 , 2 ) , r1 = new Point ( 5 , 7 ) ; Point l2 = new Point ( 3 , 4 ) , r2 = new Point ( 6 , 9 ) ; System . out . println ( overlappingArea ( l1 , r1 , l2 , r2 ) ) ; } }
Area of square Circumscribed by Circle | Java program to find Area of square Circumscribed by Circle ; Function to find area of square ; Driver code ; Radius of a circle ; Call Function to find an area of square
class GFG { static int find_Area ( int r ) { return ( 2 * r * r ) ; } public static void main ( String [ ] args ) { int r = 3 ; System . out . print ( " ▁ Area ▁ of ▁ square ▁ = ▁ " + find_Area ( r ) ) ; } }
Check whether triangle is valid or not if sides are given | Java program to check validity of any triangle ; Function to calculate for validity ; check condition ; Driver function ; function calling and print output
public class GFG { public static int checkValidity ( int a , int b , int c ) { if ( a + b <= c a + c <= b b + c <= a ) return 0 ; else return 1 ; } public static void main ( String args [ ] ) { int a = 7 , b = 10 , c = 5 ; if ( ( checkValidity ( a , b , c ) ) == 1 ) System . out . print ( " Valid " ) ; else System . out . print ( " Invalid " ) ; } }
Print Longest Palindromic Subsequence | Java program to print longest palindromic subsequence ; Returns LCS X and Y ; Following steps build L [ m + 1 ] [ n + 1 ] in bottom up fashion . Note that L [ i ] [ j ] contains length of LCS of X [ 0. . i - 1 ] and Y [ 0. . j - 1 ] ; Following code is used to print LCS ; Create a String length index + 1 and fill it with \ 0 ; Start from the right - most - bottom - most corner and one by one store characters in lcs [ ] ; If current character in X [ ] and Y are same , then current character is part of LCS ; Put current character in result ; reduce values of i , j and index ; } If not same , then find the larger of two and go in the direction of larger value ; Returns longest palindromic subsequence of str ; Find reverse of str ; Return LCS of str and its reverse ; convert String to character array by using toCharArray ; Driver program to test above function
class GFG { static String lcs ( String a , String b ) { int m = a . length ( ) ; int n = b . length ( ) ; char X [ ] = a . toCharArray ( ) ; char Y [ ] = b . toCharArray ( ) ; int L [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) { L [ i ] [ j ] = 0 ; } else if ( X [ i - 1 ] == Y [ j - 1 ] ) { L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; } else { L [ i ] [ j ] = Math . max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } } int index = L [ m ] [ n ] ; char [ ] lcs = new char [ index + 1 ] ; int i = m , j = n ; while ( i > 0 && j > 0 ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { lcs [ index - 1 ] = X [ i - 1 ] ; i -- ; j -- ; index -- ; else if ( L [ i - 1 ] [ j ] > L [ i ] [ j - 1 ] ) { i -- ; } else { j -- ; } } String ans = " " ; for ( int x = 0 ; x < lcs . length ; x ++ ) { ans += lcs [ x ] ; } return ans ; } static String longestPalSubseq ( String str ) { String rev = str ; rev = reverse ( rev ) ; return lcs ( str , rev ) ; } static String reverse ( String str ) { String ans = " " ; char [ ] try1 = str . toCharArray ( ) ; for ( int i = try1 . length - 1 ; i >= 0 ; i -- ) { ans += try1 [ i ] ; } return ans ; } public static void main ( String [ ] args ) { String str = " GEEKSFORGEEKS " ; System . out . println ( longestPalSubseq ( str ) ) ; } }
Find the Surface area of a 3D figure | Java program to find the Surface area of a 3D figure ; Declaring the size of the matrix ; Absolute Difference between the height of two consecutive blocks ; Function To calculate the Total surfaceArea . ; Traversing the matrix . ; If we are traveling the topmost row in the matrix , we declare the wall above it as 0 as there is no wall above it . ; If we are traveling the leftmost column in the matrix , we declare the wall left to it as 0 as there is no wall left it . ; If its not the topmost row ; If its not the leftmost column ; Summing up the contribution of by the current block ; If its the rightmost block of the matrix it will contribute area equal to its height as a wall on the right of the figure ; If its the lowest block of the matrix it will contribute area equal to its height as a wall on the bottom of the figure ; Adding the contribution by the base and top of the figure ; Driver code
class GFG { static final int M = 3 ; static final int N = 3 ; static int contribution_height ( int current , int previous ) { return Math . abs ( current - previous ) ; } static int surfaceArea ( int A [ ] [ ] ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { int up = 0 ; int left = 0 ; if ( i > 0 ) up = A [ i - 1 ] [ j ] ; if ( j > 0 ) left = A [ i ] [ j - 1 ] ; ans += contribution_height ( A [ i ] [ j ] , up ) + contribution_height ( A [ i ] [ j ] , left ) ; if ( i == N - 1 ) ans += A [ i ] [ j ] ; if ( j == M - 1 ) ans += A [ i ] [ j ] ; } } ans += N * M * 2 ; return ans ; } public static void main ( String [ ] args ) { int A [ ] [ ] = { { 1 , 3 , 4 } , { 2 , 2 , 3 } , { 1 , 2 , 4 } } ; System . out . println ( surfaceArea ( A ) ) ; } }
Program to calculate area and volume of a Tetrahedron | Java Program to Calculate area of tetrahedron ; Utility Function ; Driver code
import java . util . * ; import java . lang . * ; class GFG { public static double area_of_tetrahedron ( int side ) { return ( Math . sqrt ( 3 ) * ( side * side ) ) ; } public static void main ( String [ ] args ) { int side = 3 ; System . out . println ( " Area ▁ of ▁ Tetrahedron ▁ = " + area_of_tetrahedron ( side ) ) ; } }
Program to calculate area and volume of a Tetrahedron | Java code to find the volume of a tetrahedron ; Function to calculate volume ; Driver Code
import java . io . * ; class Tetrahedron { static double vol_tetra ( int side ) { double volume = ( Math . pow ( side , 3 ) / ( 6 * Math . sqrt ( 2 ) ) ) ; return volume ; } public static void main ( String [ ] args ) { int side = 3 ; double vol = vol_tetra ( side ) ; vol = ( double ) Math . round ( vol * 100 ) / 100 ; System . out . println ( vol ) ; } }
Program to find slope of a line | Java program for slope of line ; function to find the slope of a straight line ; driver code to check the above function
import java . util . * ; class GFG { static float slope ( float x1 , float y1 , float x2 , float y2 ) { if ( x1 == x2 ) return Integer . MAX_VALUE ; return ( y2 - y1 ) / ( x2 - x1 ) ; } public static void main ( String [ ] args ) { float x1 = 4 , y1 = 2 ; float x2 = 2 , y2 = 5 ; System . out . print ( " Slope ▁ is : ▁ " + slope ( x1 , y1 , x2 , y2 ) ) ; } }
Program to calculate area and perimeter of equilateral triangle | Java Program to find area and perimeter of equilateral triangle ; Function to calculate Area of equilateral triangle ; Function to calculate Perimeter of equilateral triangle ; Driver Code
import java . io . * ; class GFG { static float area_equi_triangle ( float side ) { return ( float ) ( ( ( Math . sqrt ( 3 ) ) / 4 ) * side * side ) ; } static float peri_equi_triangle ( float side ) { return 3 * side ; } public static void main ( String arg [ ] ) { float side = 4 ; System . out . print ( " Area ▁ of ▁ Equilateral ▁ Triangle : " ) ; System . out . println ( area_equi_triangle ( side ) ) ; System . out . print ( " Perimeter ▁ of ▁ Equilateral ▁ Triangle : " ) ; System . out . println ( peri_equi_triangle ( side ) ) ; } }
Program for Volume and Surface Area of Cuboid | Java program to find volume and total surface area of cuboid ; utility function ; Driver code
class GFG { static double areaCuboid ( double l , double h , double w ) { return ( l * h * w ) ; } static double surfaceAreaCuboid ( double l , double h , double w ) { return ( 2 * l * w + 2 * w * h + 2 * l * h ) ; } public static void main ( String [ ] args ) { double l = 1 ; double h = 5 ; double w = 7 ; System . out . println ( " Area ▁ = ▁ " + areaCuboid ( l , h , w ) ) ; System . out . println ( " Total ▁ Surface ▁ Area ▁ = ▁ " + surfaceAreaCuboid ( l , h , w ) ) ; } }
Program to find Circumference of a Circle | Java program to find circumference of circle ; utility function ; driver function
import java . io . * ; class Geometry { static double circumference ( double r ) { double PI = 3.1415 ; double cir = 2 * PI * r ; return cir ; } public static void main ( String [ ] args ) { double r = 5 ; double result = Math . round ( circumference ( r ) * 1000 ) / 1000.0 ; System . out . println ( " Circumference ▁ = ▁ " + result ) ; } }
Program to check if three points are collinear | Slope based solution to check if three points are collinear . ; function to check if point collinear or not ; Driver Code
import java . io . * ; class GFG { static void cool_line ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { if ( ( y3 - y2 ) * ( x2 - x1 ) == ( y2 - y1 ) * ( x3 - x2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int a1 = 1 , a2 = 1 , a3 = 0 , b1 = 1 , b2 = 6 , b3 = 9 ; cool_line ( a1 , b1 , a2 , b2 , a3 , b3 ) ; } }
Number of rectangles in N * M grid | JAVA Code to count number of rectangles in N * M grid ; Driver code
import java . util . * ; class GFG { public static long rectCount ( int n , int m ) { return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ; } public static void main ( String [ ] args ) { int n = 5 , m = 4 ; System . out . println ( rectCount ( n , m ) ) ; } }
Number of unique rectangles formed using N unit squares | Java program to count rotationally equivalent rectangles with n unit squares ; height >= length is maintained ; driver code
class GFG { static int countRect ( int n ) { int ans = 0 ; for ( int length = 1 ; length <= Math . sqrt ( n ) ; ++ length ) for ( int height = length ; height * length <= n ; ++ height ) ans ++ ; return ans ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . print ( countRect ( n ) ) ; } }
Find the Missing Point of Parallelogram | Java program to find missing point of a parallelogram ; main method ; coordinates of A ; coordinates of B ; coordinates of C
import java . io . * ; class GFG { public static void main ( String [ ] args ) { int ax = 5 , ay = 0 ; int bx = 1 , by = 1 ; int cx = 2 , cy = 5 ; System . out . println ( ax + ( cx - bx ) + " , ▁ " + ay + ( cy - by ) ) ; } }
Represent a given set of points by the best possible straight line | Java Program to find m and c for a straight line given , x and y ; function to calculate m and c that best fit points represented by x [ ] and y [ ] ; Driver main function
import java . io . * ; import static java . lang . Math . pow ; public class A { static void bestApproximate ( int x [ ] , int y [ ] ) { int n = x . length ; double m , c , sum_x = 0 , sum_y = 0 , sum_xy = 0 , sum_x2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum_x += x [ i ] ; sum_y += y [ i ] ; sum_xy += x [ i ] * y [ i ] ; sum_x2 += pow ( x [ i ] , 2 ) ; } m = ( n * sum_xy - sum_x * sum_y ) / ( n * sum_x2 - pow ( sum_x , 2 ) ) ; c = ( sum_y - m * sum_x ) / n ; System . out . println ( " m ▁ = ▁ " + m ) ; System . out . println ( " c ▁ = ▁ " + c ) ; } public static void main ( String args [ ] ) { int x [ ] = { 1 , 2 , 3 , 4 , 5 } ; int y [ ] = { 14 , 27 , 40 , 55 , 68 } ; bestApproximate ( x , y ) ; } }
Check for star graph | Java program to find whether given graph is star or not ; define the size of incidence matrix ; function to find star graph ; initialize number of vertex with deg 1 and n - 1 ; check for S1 ; check for S2 ; check for Sn ( n > 2 ) ; Driver code
import java . io . * ; class GFG { static int size = 4 ; static boolean checkStar ( int mat [ ] [ ] ) { int vertexD1 = 0 , vertexDn_1 = 0 ; if ( size == 1 ) return ( mat [ 0 ] [ 0 ] == 0 ) ; if ( size == 2 ) return ( mat [ 0 ] [ 0 ] == 0 && mat [ 0 ] [ 1 ] == 1 && mat [ 1 ] [ 0 ] == 1 && mat [ 1 ] [ 1 ] == 0 ) ; for ( int i = 0 ; i < size ; i ++ ) { int degreeI = 0 ; for ( int j = 0 ; j < size ; j ++ ) if ( mat [ i ] [ j ] == 1 ) degreeI ++ ; if ( degreeI == 1 ) vertexD1 ++ ; else if ( degreeI == size - 1 ) vertexDn_1 ++ ; } return ( vertexD1 == ( size - 1 ) && vertexDn_1 == 1 ) ; } public static void main ( String args [ ] ) { int mat [ ] [ ] = { { 0 , 1 , 1 , 1 } , { 1 , 0 , 0 , 0 } , { 1 , 0 , 0 , 0 } , { 1 , 0 , 0 , 0 } } ; if ( checkStar ( mat ) ) System . out . print ( " Star ▁ Graph " ) ; else System . out . print ( " Not ▁ a ▁ Star ▁ Graph " ) ; } }
Find all angles of a given triangle | Java Code to find all three angles of a triangle given coordinate of all three vertices ; returns square of distance b / w two points ; Square of lengths be a2 , b2 , c2 ; length of sides be a , b , c ; From Cosine law ; Converting to degree ; printing all the angles ; Driver method
import java . awt . Point ; import static java . lang . Math . PI ; import static java . lang . Math . sqrt ; import static java . lang . Math . acos ; class Test { static int lengthSquare ( Point p1 , Point p2 ) { int xDiff = p1 . x - p2 . x ; int yDiff = p1 . y - p2 . y ; return xDiff * xDiff + yDiff * yDiff ; } static void printAngle ( Point A , Point B , Point C ) { int a2 = lengthSquare ( B , C ) ; int b2 = lengthSquare ( A , C ) ; int c2 = lengthSquare ( A , B ) ; float a = ( float ) sqrt ( a2 ) ; float b = ( float ) sqrt ( b2 ) ; float c = ( float ) sqrt ( c2 ) ; float alpha = ( float ) acos ( ( b2 + c2 - a2 ) / ( 2 * b * c ) ) ; float betta = ( float ) acos ( ( a2 + c2 - b2 ) / ( 2 * a * c ) ) ; float gamma = ( float ) acos ( ( a2 + b2 - c2 ) / ( 2 * a * b ) ) ; alpha = ( float ) ( alpha * 180 / PI ) ; betta = ( float ) ( betta * 180 / PI ) ; gamma = ( float ) ( gamma * 180 / PI ) ; System . out . println ( " alpha ▁ : ▁ " + alpha ) ; System . out . println ( " betta ▁ : ▁ " + betta ) ; System . out . println ( " gamma ▁ : ▁ " + gamma ) ; } public static void main ( String [ ] args ) { Point A = new Point ( 0 , 0 ) ; Point B = new Point ( 0 , 1 ) ; Point C = new Point ( 1 , 0 ) ; printAngle ( A , B , C ) ; } }
Triangle with no point inside | Java program to find triangle with no point inside ; method to get square of distance between ( x1 , y1 ) and ( x2 , y2 ) ; Method prints points which make triangle with no point inside ; any point can be chosen as first point of triangle ; choose nearest point as second point of triangle ; Get distance from first point and choose nearest one ; Pick third point by finding the second closest point with different slope . ; if already chosen point then skip them ; get distance from first point ; here cross multiplication is compared instead of division comparison ; Driver code
import java . io . * ; class GFG { static int getDistance ( int x1 , int y1 , int x2 , int y2 ) { return ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 ) ; } static void triangleWithNoPointInside ( int points [ ] [ ] , int N ) { int first = 0 ; int second = 0 ; int third = 0 ; int minD = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == first ) continue ; int d = getDistance ( points [ i ] [ 0 ] , points [ i ] [ 1 ] , points [ first ] [ 0 ] , points [ first ] [ 1 ] ) ; if ( minD > d ) { minD = d ; second = i ; } } minD = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == first i == second ) continue ; int d = getDistance ( points [ i ] [ 0 ] , points [ i ] [ 1 ] , points [ first ] [ 0 ] , points [ first ] [ 1 ] ) ; if ( ( points [ i ] [ 0 ] - points [ first ] [ 0 ] ) * ( points [ second ] [ 1 ] - points [ first ] [ 1 ] ) != ( points [ second ] [ 0 ] - points [ first ] [ 0 ] ) * ( points [ i ] [ 1 ] - points [ first ] [ 1 ] ) && minD > d ) { minD = d ; third = i ; } } System . out . println ( points [ first ] [ 0 ] + " , ▁ " + points [ first ] [ 1 ] ) ; System . out . println ( points [ second ] [ 0 ] + " , ▁ " + points [ second ] [ 1 ] ) ; System . out . println ( points [ third ] [ 0 ] + " , ▁ " + points [ third ] [ 1 ] ) ; } public static void main ( String [ ] args ) { int points [ ] [ ] = { { 0 , 0 } , { 0 , 2 } , { 2 , 0 } , { 2 , 2 } , { 1 , 1 } } ; int N = points . length ; triangleWithNoPointInside ( points , N ) ; } }