Check if two numbers have same number of digits | Java implementation of the approach ; Function that return true if A and B have same number of digits ; Both must be 0 now if they had same lengths ; Driver code
import java . io . * ; class GFG { static boolean sameLength ( int A , int B ) { while ( ( A > 0 ) && ( B > 0 ) ) { A = A / 10 ; B = B / 10 ; } if ( ( A == 0 ) && ( B == 0 ) ) return true ; return false ; } public static void main ( String [ ] args ) { int A = 21 , B = 1 ; if ( sameLength ( A , B ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }