Check if a right | Java program to implement the above approach ; Function to check if N is a perfect square number or not ; If N is a non positive integer ; Stores square root of N ; Check for perfect square ; If N is not a perfect square number ; Function to check if given two sides of a triangle forms a right - angled triangle ; If the value of ( A * A + B * B ) is a perfect square number ; Update checkTriangle ; If the value of ( A * A - B * B ) is a perfect square number ; Update checkTriangle ; If the value of ( B * B - A * A ) is a perfect square number ; Update checkTriangle ; Driver Code ; If the given two sides of a triangle forms a right - angled triangle ; Otherwise
import java . io . * ; import java . util . * ; class GFG { static int checkPerfectSquare ( int N ) { if ( N <= 0 ) { return 0 ; } double sq = Math . sqrt ( N ) ; if ( Math . floor ( sq ) == Math . ceil ( sq ) ) { return 1 ; } return 0 ; } static boolean checktwoSidesareRighTriangle ( int A , int B ) { boolean checkTriangle = false ; if ( checkPerfectSquare ( A * A + B * B ) != 0 ) { checkTriangle = true ; } if ( checkPerfectSquare ( A * A - B * B ) != 0 ) { checkTriangle = true ; } if ( checkPerfectSquare ( B * B - A * A ) != 0 ) { checkTriangle = true ; } return checkTriangle ; } public static void main ( String [ ] args ) { int A = 3 , B = 4 ; if ( checktwoSidesareRighTriangle ( A , B ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }