Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class hw2{
- public static void main(String[] args){
- Scanner scan = new Scanner(System.in);
- int b = scan.nextInt();
- int[] a = new int[b];
- int k = 0;
- for(int i=0; i<a.length; i++){
- a[i]=scan.nextInt();
- }
- if(a.length%2==1){
- for(int i=0; i<a.length-1; i+=2){
- int t = a[i];
- a[i] = a[i+1];
- a[i+1] = t;
- }
- }else{
- for(int i=0; i<a.length; i+=2){
- int t = a[i];
- a[i] = a[i+1];
- a[i+1] = t;
- }
- }
- for(int i=0; i<a.length; i++){
- System.out.print(a[i]+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement