Find the good permutation of first N natural numbers | Java implementation of the approach ; Function to print the good permutation of first N natural numbers ; If n is odd ; Otherwise ; Driver code
class GFG { static int printPermutation ( int n ) { if ( n % 2 != 0 ) { System . out . println ( " - 1" ) ; } else for ( int i = 1 ; i <= n / 2 ; i ++ ) { System . out . print ( 2 * i + " ▁ " + ( ( 2 * i ) - 1 ) + " ▁ " ) ; } return n ; } public static void main ( String [ ] args ) { int n = 4 ; printPermutation ( n ) ; } }