Home  >  Article  >  Backend Development  >  Irregular two-dimensional array

Irregular two-dimensional array

WBOY
WBOYOriginal
2016-07-25 09:08:14889browse
  1. package com.sjzmlb.test;
  2. /**
  3. *
  4. * @author sjzmlb
  5. *
  6. */
  7. public class TestArray {
  8. public static void main(String[] args) {
  9. // -----Irregular two-dimensional Array----
  10. int[][] ints = new int[5][];
  11. for (int i = 0; i < 5; i++) {
  12. ints[i] = new int[i + 1] ;
  13. for (int j = 0; j < i + 1; j++) {
  14. ints[i][j] = i + 1;
  15. }
  16. }
  17. for (int[] i : ints) {
  18. for ( int j : i) {
  19. System.out.print(j);
  20. }
  21. System.out.println();
  22. }
  23. }
  24. }
Copy code
  1. 1
  2. 22
  3. 333
  4. 4444
  5. 55555
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn