fork download
  1. class MatrixCode {
  2.  
  3. static int max(int x,int y)
  4. {
  5. if(x>y)
  6. {
  7. return x;
  8. }
  9. else
  10. {
  11. return y;
  12. }
  13. }
  14.  
  15. static int min(int x,int y)
  16. {
  17. if(x<y)
  18. {
  19. return x;
  20. }
  21. else
  22. {
  23. return y;
  24. }
  25. }
  26.  
  27.  
  28. public static void main(String[] args) {
  29. // TODO Auto-generated method stub
  30.  
  31.  
  32. int [][] x = {{1,2,3},{4,5,6},{7,8,9}};
  33. int n= 3;
  34. for(int i=0;i<2*n-1;i++)
  35. {
  36. for(int j=max(i-(n-1),0);j<min(i,n-1);j++)
  37. {
  38. System.out.print(x[j][i] + " ");
  39. }
  40. System.out.println();
  41. }
  42.  
  43. }
  44.  
  45. }
  46.  
Runtime error #stdin #stdout #stderr 0.04s 4386816KB
stdin
Standard input is empty
stdout
2 
3 6 
stderr
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
	at MatrixCode.main(Main.java:38)