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 ; Find the number of digit in B ; Subtract B from A ; Returns true , if B is a suffix of A ; Driver code ; Given numbers ; Function call ; If B is a suffix of A , then print " Yes "
import java . util . * ; class GFG { static boolean checkSuffix ( int A , int B ) { int digit_B = ( int ) ( Math . log10 ( B ) + 1 ) ; A -= B ; return ( A % ( int ) ( Math . pow ( 10 , digit_B ) ) > 0 ) ; } 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 . print ( " No " ) ; } } }