本文介绍了为什么输出此代码111111?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这是代码。我试图解决它,但我无法理解它的输出是111111?

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) {
        int list[] = {1, 2, 3, 4, 5, 6};

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

        for (int i = 0; i < list.length; i++)
          System.out.print(list[i] + " ");
      }
    }


推荐答案

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

相当于:

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

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

知道了吗?

这篇关于为什么输出此代码111111?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:58