10 's Complement of a decimal number | Java program to find 10 's complement ; Function to find 10 's complement ; Calculating total digits in num ; restore num ; calculate 10 's complement ; Driver code
import java . io . * ; class GFG { static int complement ( int num ) { int i , len = 0 , temp , comp ; temp = num ; while ( true ) { len ++ ; num = num / 10 ; if ( Math . abs ( num ) == 0 ) break ; } num = temp ; comp = ( int ) Math . pow ( 10 , len ) - num ; return comp ; } public static void main ( String [ ] args ) { System . out . println ( complement ( 25 ) ) ; System . out . println ( complement ( 456 ) ) ; } }