Generate a sequence such that float division of array elements is maximized | Java program for the above approach ; Function to place the parenthesis such that the result is maximized ; Store the required string ; Add the first integer to string ; If the size of array is 1 ; If the size of array is 2 , print the 1 st integer followed by / operator followed by the next integer ; If size of array is exceeds two , print 1 st integer concatenated with operators ' / ' , ' ( ' and next integers with the operator ' / ' ; Add parenthesis at the end ; Print the final expression ; Driver Code
import java . io . * ; class GFG { static void generateSequence ( int arr [ ] , int n ) { String ans ; ans = Integer . toString ( arr [ 0 ] ) ; if ( n == 1 ) System . out . println ( ans ) ; else if ( n == 2 ) { System . out . println ( ans + " / " + Integer . toString ( arr [ 1 ] ) ) ; } else { ans += " / ( " + Integer . toString ( arr [ 1 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { ans += " / " + Integer . toString ( arr [ i ] ) ; } ans += " ) " ; System . out . println ( ans ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1000 , 100 , 10 , 2 } ; int N = arr . length ; generateSequence ( arr , N ) ; } }