Represent a number as the sum of positive numbers ending with 9 | Java program for the above approach ; Function to find the minimum count of numbers ending with 9 to form N ; Extract last digit of N ; Calculate the last digit ; If the last digit satisfies the condition ; Driver Code
import java . util . * ; class GFG { static int minCountOfNumbers ( int N ) { int k = N % 10 ; int z = N - ( 9 * ( 9 - k ) ) ; if ( z >= 9 && z % 10 == 9 ) { return 10 - k ; } else return - 1 ; } public static void main ( String [ ] args ) { int N = 156 ; System . out . print ( minCountOfNumbers ( N ) ) ; } }