TheBulgarianWolf

Zig-Zag Arrays

Apr 27th, 2020
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3.  
  4. public class SoftUni {
  5.    
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         String line1 = "";
  9.         String line2 = "";
  10.         System.out.print("Enter the number of lines here: ");
  11.         int lines = Integer.parseInt(sc.nextLine());
  12.         for(int i = 0;i<lines;i++){
  13.             String[] line = sc.nextLine().split(" ");
  14.             int[] arr = Arrays.stream(line).mapToInt(e -> Integer.parseInt(e)).toArray();
  15.             if(i % 2 == 0){
  16.                 line1 += arr[0] + " ";
  17.                 line2 += arr[1] + " ";
  18.             }
  19.             else{
  20.                 line1 += arr[1] + " ";
  21.                 line2 += arr[0] + " ";
  22.             }
  23.            
  24.         }
  25.        
  26.         System.out.println(line1);
  27.         System.out.println(line2);
  28.     }
  29.  
  30. }
Add Comment
Please, Sign In to add comment