Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class ZigZag_Print {
- public static void main(String[] args) throws IOException {
- BufferedReader reader =
- new BufferedReader(
- new InputStreamReader(System.in));
- System.out.println("Enter number of rows!");
- int n = Integer.parseInt(reader.readLine());
- String firstRow = " ";
- String secondRow = " ";
- for (int i = 0; i < n; i++) {
- System.out.println("Enter two numbers!");
- String[] input = reader.readLine().split("\\s+");
- if (i % 2 == 0) {
- firstRow += input[0] + " ";
- secondRow += input[1] + " ";
- } else {
- firstRow += input[1] + " ";
- secondRow += input[0] + " ";
- }
- }
- System.out.println(String.join(" ", firstRow).trim());
- System.out.println(String.join(" ", secondRow).trim());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement