Number formed by adding product of its max and min digit K times | Java program for the above approach ; Function to find the formed number ; K -- ; M ( 1 ) = N ; Check if minimum digit is 0 ; Function that returns the product of maximum and minimum digit of N number . ; Finds the last digit . ; Moves to next digit ; Driver code
import java . io . * ; import java . util . * ; class GFG { public static int formed_no ( int N , int K ) { if ( K == 1 ) { return N ; } int answer = N ; while ( K != 0 ) { int a_current = prod_of_max_min ( answer ) ; if ( a_current == 0 ) break ; answer += a_current ; } return answer ; } static int prod_of_max_min ( int n ) { int largest = 0 ; int smallest = 10 ; while ( n != 0 ) { int r = n % 10 ; largest = Math . max ( r , largest ) ; smallest = Math . min ( r , smallest ) ; n = n / 10 ; } return largest * smallest ; } public static void main ( String [ ] args ) { int N = 487 , K = 100000000 ; System . out . println ( formed_no ( N , K ) ) ; } }