我已经在Java中编写了以下类
public class Factorial
{
final String[] promotion: {"watch", "on", "youtube:", "Mickey en de stomende drol", (https://www.youtube.com/watch?v=a3leCIk2eyQ)"};
public static void main(String[] args)
{
System.out.println(shoutPromotion(promotion));
}
public static String shoutPromotion(String[] promotion)
{ String result = "";
for(int i = 1; i < promotion.length; i++)
result += promotion[i] + " ";
return result;
}
}
但是当我运行程序时,我在控制台中看到以下输出:
在youtube上:Mickey en de stomende drol(https://www.youtube.com/watch?v=a3leCIk2eyQ)
守望这个词消失了。这是怎么来的?
答案 0 :(得分:3)
数组索引以0而不是1开头。
此
for(int i = 1; i < promotion.length; i++)
将其更改为
for(int i = 0; i < promotion.length; i++)