Nth term of a sequence formed by sum of current term with product of its largest and smallest digit | Java program for the above approach . ; Function to find integer ; Because 1 st integer is K itself ; Initialize min_d and max_d ; Updating min_d and max_d ; Break if min digit is 0 ; Driver code
import java . util . * ; class GFG { static int find ( int K , int N ) { N -- ; while ( N -- != 0 ) { int curr_term = K ; int min_d = 9 ; int max_d = 0 ; while ( curr_term > 0 ) { int r = curr_term % 10 ; min_d = Math . min ( min_d , r ) ; max_d = Math . max ( max_d , r ) ; curr_term = curr_term / 10 ; } if ( min_d == 0 ) { break ; } K = K + min_d * max_d ; } return K ; } public static void main ( String [ ] args ) { int K = 487 ; int N = 2 ; System . out . print ( find ( K , N ) + "NEW_LINE"); } }