Find the remaining vertices of a square from two given vertices | Java program for the above approach ; Function to find the remaining vertices of a square ; Check if the x - coordinates are equal ; Check if the y - coordinates are equal ; If the the given coordinates forms a diagonal of the square ; Otherwise ; Square does not exist ; Driver Code ; Given two vertices
import java . util . * ; class GFG { static void findVertices ( int x1 , int y1 , int x2 , int y2 ) { if ( x1 == x2 ) { System . out . print ( ( x1 + y2 - y1 ) + " , ▁ " + y1 + "NEW_LINE"); System . out . print ( ( x2 + y2 - y1 ) + " , ▁ " + y2 ) ; } else if ( y1 == y2 ) { System . out . print ( x1 + " , ▁ " + ( y1 + x2 - x1 ) + "NEW_LINE"); System . out . print ( x2 + " , ▁ " + ( y2 + x2 - x1 ) ) ; } else if ( Math . abs ( x2 - x1 ) == Math . abs ( y2 - y1 ) ) { System . out . print ( x1 + " , ▁ " + y2 + "NEW_LINE"); System . out . print ( x2 + " , ▁ " + y1 ) ; } else System . out . print ( " - 1" ) ; } public static void main ( String [ ] args ) { int x1 = 1 , y1 = 2 ; int x2 = 3 , y2 = 4 ; findVertices ( x1 , y1 , x2 , y2 ) ; } }