Advertisement
Krassi_Daskalova

ZigZagArrays

Jun 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ZigZagArrays {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = Integer.parseInt(scanner.nextLine());
  7. String[] first = new String[n];
  8. String[] second = new String[n];
  9.  
  10. for (int i = 1; i <= n; i++) {
  11. String[] input = scanner.nextLine().split(" ");
  12. if (i % 2 == 0) {
  13. first[i - 1] = input[1];
  14. second[i - 1] = input[0];
  15. } else {
  16. first[i - 1] = input[0];
  17. second[i - 1] = input[1];
  18. }
  19. }
  20. System.out.println(String.join(" ", first));
  21. System.out.println(String.join(" ", second));
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement