Why is the output of this code 111111?

后端 未结 9 1983
星月不相逢
星月不相逢 2021-01-13 20:10

This is the code. I tried to solve it, but I can\'t understand how its output is 111111?

public class Test { 
      public static void main(String[] args) {
         


        
9条回答
  •  半阙折子戏
    2021-01-13 21:03

    for (int i = 1; i < list.length; i++)
          list[i] = list[i - 1];
    

    is equivalent to:

    list[1] = list[1-1] = list[0] = 1
    list[2] = list[2-1] = list[1] = 1
    list[3] = list[3-1] = list[2] = 1
    list[4] = list[4-1] = list[3] = 1
    list[5] = list[5-1] = list[4] = 1

    Got it?

提交回复
热议问题