Minimum sum of two numbers formed from digits of an array | Java program to find minimum sum of two numbers formed from all digits in a given array . ; Returns sum of two numbers formed from all digits in a [ ] ; sort the elements ; Driver code
import java . util . Arrays ; public class AQRQ { static int minSum ( int a [ ] , int n ) { Arrays . sort ( a ) ; int num1 = 0 ; int num2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) num1 = num1 * 10 + a [ i ] ; else num2 = num2 * 10 + a [ i ] ; } return num2 + num1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 3 , 0 , 7 , 4 } ; int n = arr . length ; System . out . println ( " The ▁ required ▁ sum ▁ is ▁ " + minSum ( arr , n ) ) ; } }