MMTTMM
您可以尝试流:import java.util.stream.Collectors;import java.util.stream.IntStream;IntStream.range(0, 15).forEach( x -> System.out.println( IntStream.rangeClosed(0, x) .mapToObj(String::valueOf) .collect(Collectors.joining(", "))));输出:00, 10, 1, 20, 1, 2, 30, 1, 2, 3, 40, 1, 2, 3, 4, 50, 1, 2, 3, 4, 5, 60, 1, 2, 3, 4, 5, 6, 70, 1, 2, 3, 4, 5, 6, 7, 80, 1, 2, 3, 4, 5, 6, 7, 8, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 110, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 120, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 130, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
慕神8447489
你应该使用Arrays.toString,像这样:import java.util.Arrays;public class Main { public static void main(String[] args) { // TODO Auto-generated method stub int[] table = new int[11]; for ( int i = 0; i <=10; i++){ table[i] = i; System.out.println(Arrays.toString(table)); } }}但是,这将打印整个数组,因为它正在被填充:[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0][0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0][0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0][0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0][0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0][0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0][0, 1, 2, 3, 4, 5, 6, 0, 0, 0, 0][0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0][0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0][0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0][0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]如果您只想填充到目前为止的元素,则需要更多的参与:import java.util.Arrays;public class Main { public static void main(String[] args) { // TODO Auto-generated method stub int[] table = new int[11]; for ( int i = 0; i <=10; i++){ table[i] = i; for(int j = 0; j <= i; j++) { System.out.print((j == 0 ? "" : ", ") + table[j]); } System.out.println(); } }}输出:00, 10, 1, 20, 1, 2, 30, 1, 2, 3, 40, 1, 2, 3, 4, 50, 1, 2, 3, 4, 5, 60, 1, 2, 3, 4, 5, 6, 70, 1, 2, 3, 4, 5, 6, 7, 80, 1, 2, 3, 4, 5, 6, 7, 8, 90, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10