Possible pairs forming a Pythagorean Triple with a given value | Java program to compute all the possible pairs that forms a pythagorean triple with a given value ; Function to generate all possible pairs ; Vector to store all the possible pairs ; Checking all the possible pair in the range of [ 1 , c ) ; If the pair satisfies the condition push it in the vector ; Driver code ; If no valid pair exist ; Print all valid pairs
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static Vector < pair > Pairs ( int C ) { Vector < pair > ans = new Vector < pair > ( ) ; for ( int i = 1 ; i < C ; i ++ ) { for ( int j = i + 1 ; j < C ; j ++ ) { if ( ( i * i ) + ( j * j ) == ( C * C ) ) { ans . add ( new pair ( i , j ) ) ; } } } return ans ; } public static void main ( String [ ] args ) { int C = 13 ; Vector < pair > ans = Pairs ( C ) ; if ( ans . size ( ) == 0 ) { System . out . print ( " No ▁ valid ▁ pair ▁ " + " exist " + "NEW_LINE"); return ; } for ( pair i : ans ) { System . out . print ( " ( " + i . first + " , ▁ " + i . second + " ) " + "NEW_LINE"); } } }