Check if a number ends with another number or not | Java program for the above approach ; Function to check if B is a suffix of A or not ; Convert numbers into strings ; Find the lengths of strings s1 and s2 ; Base case ; Traverse the strings s1 & s2 ; If at any index characters are unequals then return false ; Return true ; Driver code ; Given numbers ; Function Call ; If B is a suffix of A , then print " Yes "
class GFG { public static boolean checkSuffix ( int A , int B ) { String s1 = String . valueOf ( A ) ; String s2 = String . valueOf ( B ) ; int n1 = s1 . length ( ) ; int n2 = s2 . length ( ) ; if ( n1 < n2 ) { return false ; } for ( int i = 0 ; i < n2 ; i ++ ) { if ( s1 . charAt ( n1 - i - 1 ) != s2 . charAt ( n2 - i - 1 ) ) { return false ; } } return true ; } public static void main ( String [ ] args ) { int A = 12345 , B = 45 ; boolean result = checkSuffix ( A , B ) ; if ( result ) { System . out . print ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }