Advertisement
Kancho

ZigZag_Print_New

Jun 16th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class ZigZag_Print {
  6. public static void main(String[] args) throws IOException {
  7.  
  8. BufferedReader reader =
  9. new BufferedReader(
  10. new InputStreamReader(System.in));
  11.  
  12. System.out.println("Enter number of rows!");
  13. int n = Integer.parseInt(reader.readLine());
  14.  
  15. String firstRow = " ";
  16. String secondRow = " ";
  17. for (int i = 0; i < n; i++) {
  18. System.out.println("Enter two numbers!");
  19. String[] input = reader.readLine().split("\\s+");
  20. if (i % 2 == 0) {
  21. firstRow += input[0] + " ";
  22. secondRow += input[1] + " ";
  23. } else {
  24. firstRow += input[1] + " ";
  25. secondRow += input[0] + " ";
  26. }
  27. }
  28. System.out.println(String.join(" ", firstRow).trim());
  29. System.out.println(String.join(" ", secondRow).trim());
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement