Maximum number by concatenating every element in a rotation of an array | Java program to print the Maximum number by concatenating every element in rotation of array ; Function to print the largest number ; store the index of largest left most digit of elements ; Iterate for all numbers ; check for the last digit ; check for the largest left most digit ; print the rotation of array ; print the rotation of array ; Driver Code
import java . util . * ; import java . lang . * ; public class GFG { static void printLargest ( int a [ ] , int n ) { int max = - 1 ; int ind = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int num = a [ i ] ; while ( num > 0 ) { int r = num % 10 ; num = num / 10 ; if ( num == 0 ) { if ( max < r ) { max = r ; ind = i ; } } } } for ( int i = ind ; i < n ; i ++ ) System . out . print ( a [ i ] ) ; for ( int i = 0 ; i < ind ; i ++ ) System . out . print ( a [ i ] ) ; } public static void main ( String args [ ] ) { int a [ ] = { 54 , 546 , 548 , 60 } ; int n = a . length ; printLargest ( a , n ) ; } }