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.  
  20. for(int j=0; j<=i; j++){
  21. if(i%2 != 0) {
  22. System.out.printf("%d ",even);
  23. even += 2;
  24. }
  25. else {
  26. System.out.printf("%d ",odd);
  27. odd += 2;
  28. }
  29. }
  30. System.out.printf("\n");
  31. }
  32.  
  33. }
  34. }
Success #stdin #stdout 0.18s 54656KB
stdin
6
stdout
1 
2 4 
3 5 7 
6 8 10 12 
9 11 13 15 17 
14 16 18 20 22 24