Print an N x M matrix such that each row and column has all the vowels in it | Java implementation of the approach ; Function to print the required matrix ; Impossible to generate the required matrix ; Store all the vowels ; Print the matrix ; Print vowels for every index ; Shift the vowels by one ; Driver code
class GFG { static void printMatrix ( int n , int m ) { if ( n < 5 m < 5 ) { System . out . print ( - 1 ) ; return ; } char [ ] s = " aeiou " . toCharArray ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { System . out . print ( s [ j % 5 ] + " ▁ " ) ; } System . out . println ( ) ; char c = s [ 0 ] ; for ( int k = 0 ; k < 4 ; k ++ ) { s [ k ] = s [ k + 1 ] ; } s [ 4 ] = c ; } } public static void main ( String [ ] args ) { int n = 5 , m = 5 ; printMatrix ( n , m ) ; } }