fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9.  
  10. public static void main (String[] args) throws java.lang.Exception {
  11.  
  12. // your code goes here
  13. Scanner sc = new Scanner(System.in);
  14. int n = sc.nextInt();
  15. int even = 2;
  16. int odd = 1;
  17.  
  18. for(int i=0; i<n; i++) {
  19. if(i%2 != 0) {
  20. for(int j=0; j<=i; j++){
  21. System.out.printf("%d ",even);
  22. even += 2;
  23. }
  24. }
  25. else {
  26. for(int j=0; j<=i; j++){
  27. System.out.printf("%d ",odd);
  28. odd += 2;
  29. }
  30. }
  31. System.out.printf("\n");
  32. }
  33.  
  34. }
  35. }
Success #stdin #stdout 0.19s 56768KB
stdin
6
stdout
1 
2 4 
3 5 7 
6 8 10 12 
9 11 13 15 17 
14 16 18 20 22 24