Print N distinct numbers following the given operations | Java implementation to print N distinct numbers ; Function to print the required array ; Check if number is a multiple of 4 ; Printing left half of the array ; Printing Right Half of the array ; Driver code
import java . util . * ; class GFG { static void printArr ( int n ) { if ( n % 4 == 0 ) { for ( int i = 1 ; i <= n / 2 ; i ++ ) System . out . print ( i * 2 + " ▁ " ) ; for ( int i = 1 ; i < n / 2 ; i ++ ) System . out . print ( i * 2 - 1 + " ▁ " ) ; System . out . println ( n + n / 2 - 1 ) ; } else System . out . print ( " - 1" ) ; } public static void main ( String [ ] args ) { int n = 22 ; printArr ( n ) ; } }