Advertisement
Ivakis

Number Table

Sep 7th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class p14_NumTable {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8.  
  9. int currentNum = 0;
  10. int step = 1;
  11.  
  12. for (int row = 1; row <= n ; row++) {
  13. currentNum = row;
  14. step = 1;
  15. for (int col = 0; col < n ; col++) {
  16.  
  17. System.out.printf("%d ", currentNum);
  18.  
  19. if (currentNum >= n){
  20. step = -1;
  21. }
  22. currentNum = currentNum + step;
  23. }
  24. System.out.println();
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement