Program to check similarity of given two triangles | Java program to check similarity between two triangles . ; Function for AAA similarity ; Check for AAA ; Function for SAS similarity ; angle b / w two smallest sides is largest . ; since we take angle b / w the sides . ; Function for SSS similarity ; Check for SSS ; Driver Code ; function call for AAA similarity ; function call for SSS similarity ; function call for SAS similarity ; Check if triangles are similar or not
import java . util . * ; class GFG1 { static int simi_aaa ( int a1 [ ] , int a2 [ ] ) { Arrays . sort ( a1 ) ; Arrays . sort ( a2 ) ; if ( a1 [ 0 ] == a2 [ 0 ] && a1 [ 1 ] == a2 [ 1 ] && a1 [ 2 ] == a2 [ 2 ] ) return 1 ; else return 0 ; } static int simi_sas ( int s1 [ ] , int s2 [ ] , int a1 [ ] , int a2 [ ] ) { Arrays . sort ( a1 ) ; Arrays . sort ( a2 ) ; Arrays . sort ( s1 ) ; Arrays . sort ( s2 ) ; if ( s1 [ 0 ] / s2 [ 0 ] == s1 [ 1 ] / s2 [ 1 ] ) { if ( a1 [ 2 ] == a2 [ 2 ] ) return 1 ; } if ( s1 [ 1 ] / s2 [ 1 ] == s1 [ 2 ] / s2 [ 2 ] ) { if ( a1 [ 0 ] == a2 [ 0 ] ) return 1 ; } if ( s1 [ 2 ] / s2 [ 2 ] == s1 [ 0 ] / s2 [ 0 ] ) { if ( a1 [ 1 ] == a2 [ 1 ] ) return 1 ; } return 0 ; } static int simi_sss ( int s1 [ ] , int s2 [ ] ) { Arrays . sort ( s1 ) ; Arrays . sort ( s2 ) ; if ( s1 [ 0 ] / s2 [ 0 ] == s1 [ 1 ] / s2 [ 1 ] && s1 [ 1 ] / s2 [ 1 ] == s1 [ 2 ] / s2 [ 2 ] && s1 [ 2 ] / s2 [ 2 ] == s1 [ 0 ] / s2 [ 0 ] ) return 1 ; return 0 ; } public static void main ( String args [ ] ) { int s1 [ ] = { 2 , 3 , 3 } ; int s2 [ ] = { 4 , 6 , 6 } ; int a1 [ ] = { 80 , 60 , 40 } ; int a2 [ ] = { 40 , 60 , 80 } ; int aaa = simi_aaa ( a1 , a2 ) ; int sss = simi_sss ( s1 , s2 ) ; int sas = simi_sas ( s1 , s2 , a1 , a2 ) ; if ( aaa == 1 sss == 1 sas == 1 ) { System . out . print ( " Triangles ▁ are ▁ " + " similar ▁ by ▁ " ) ; if ( aaa == 1 ) System . out . print ( " AAA ▁ " ) ; if ( sss == 1 ) System . out . print ( " SSS ▁ " ) ; if ( sas == 1 ) System . out . print ( " SAS . " ) ; } else System . out . println ( " Triangles ▁ are ▁ " + " not ▁ similar " ) ; } }