fork download
  1. class Main{
  2. public static void main (String[] args) throws java.lang.Exception {
  3. java.util.Scanner i = new java.util.Scanner(System.in);
  4. int n = i.nextInt();
  5. int arr[] = new int[n];
  6. for(int k = 0; k < n; k++){
  7. arr[k] = i.nextInt();
  8. }
  9. for(int k = 1; k < n; k+=2){
  10. int q = arr[k];
  11. arr[k] = arr[k-1];
  12. arr[k-1] = q;
  13. }
  14. for(int k = 0; k < n; k++){
  15. System.out.print(arr[k] + " ");
  16. }
  17. }
  18. }
Success #stdin #stdout 0.12s 35824KB
stdin
7
3 5 -7 7 5 -9 -4
stdout
5 3 7 -7 -9 5 -4