Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.StringJoiner;
- /**
- * Created by NIK on 27.11.15.
- */
- public class Main2 {
- public static void main(String[] args) {
- // income data
- String[] test = new String[] {"to", "be", "or", "not", "to", "be", "hamlet"};
- ArrayList<String> pairsTestList = new ArrayList<>();
- pairsTestList.addAll(Arrays.asList(test));
- System.out.println(pairsTestList.toString());
- System.out.println();
- // Exercise 2 doSwapPairs();
- ArrayList<String> result = new ArrayList<>();
- for (int i = 0; i<pairsTestList.size()-1; i=i+2){
- result.add(pairsTestList.get(i+1));
- result.add(pairsTestList.get(i));
- }
- // last element add if ODD
- if (pairsTestList.size()%2==1) result.add(pairsTestList.get(pairsTestList.size()-1));
- System.out.println(result.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement