Find the largest number that can be formed with the given digits | Java program to generate largest possible number with given digits ; Function to generate largest possible number with given digits ; sort the given array in ascending order and then traverse into descending ; generate the number ; Driver code
import java . * ; import java . util . Arrays ; class GFG { static int findMaxNum ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int num = arr [ 0 ] ; for ( int i = n - 1 ; i >= 0 ; i -- ) { num = num * 10 + arr [ i ] ; } return num ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 0 } ; int n = arr . length ; System . out . println ( findMaxNum ( arr , n ) ) ; } }