Count number of triangles possible with length of sides not exceeding N | Java implementation of the above approach ; Function to count total number of right angled triangle ; Initialise count with 0 ; Run three nested loops and check all combinations of sides ; Condition for right angled triangle ; Increment count ; Driver code ; Given N ; Function call
import java . io . * ; class GFG { static int right_angled ( int n ) { int count = 0 ; for ( int z = 1 ; z <= n ; z ++ ) { for ( int y = 1 ; y <= z ; y ++ ) { for ( int x = 1 ; x <= y ; x ++ ) { if ( ( x * x ) + ( y * y ) == ( z * z ) ) { count ++ ; } } } } return count ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( right_angled ( n ) ) ; } }