[cs105] nums.length&nums[i]

来源:互联网 发布:联通网络服务商电话 编辑:程序博客网 时间:2024/06/14 03:04
private void ex01()
{
int[] nums = { 8, 10, 3, 4, 12, 200 };


for (int i = nums.length - 1; i >= 1; i--)
{
System.out.println(nums.length);
if (i == 1)
{
System.out.println(nums[i]);
}
else
{
nums[i - 1] = nums[i];
System.out.format("%d,", nums[i]);
}
}

}

the output above are: 200, 200, 200, 200, 200

you should understand nums.length start counting at 1, nums[i] start counting at 0

0 0
原创粉丝点击