Find the greater number closest to N having at most one non | Java program to implement the above approach ; Function to get closest greater number with at most non zero digit ; Stores the closest greater number with at most one non - zero digit ; Stores length of str ; Append 10 to the end of resultant String ; Append n - 1 times '0' to the end of resultant String ; Driver Code
import java . util . * ; class GFG { static String closestgtNum ( String str ) { String res = " " ; int n = str . length ( ) ; if ( str . charAt ( 0 ) < '9' ) { res += ( char ) ( str . charAt ( 0 ) + 1 ) ; } else { res += ( char ) ( '1' ) ; res += ( char ) ( '0' ) ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { res += ( char ) ( '0' ) ; } return res ; } public static void main ( String [ ] args ) { String str = "120" ; System . out . print ( closestgtNum ( str ) ) ; } }