【发布时间】:2017-01-13 06:17:08
【问题描述】:
我是一名编程学生,我在这个问题上遇到了很多麻烦:
"完成一个静态方法multiplesOf,它接受两个int参数,number和count。方法体必须返回一个int数组,其中包含number的第一个count倍数。例如,
multiplesOf(5, 4) 应该返回数组 { 5, 10, 15, 20 } multiplesOf(11, 3) 应该返回数组 { 11, 22, 33 } multiplesOf(1, 15) 应该返回数组 { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
您不得在您的方法中使用 System.out.print 或 System.out.println。”
这是我当前的代码:
public static void main(String[] args) {
multiplesOf(5,4);
}
public static int[] multiplesOf (int number, int count) {
int[] a = new int[count];
a[0]= number;
for(int i = 0; i<count; i++) {
a[i] = (a[i]*count);
}
return a;
}
我一直试图弄清楚为什么数组“a”仍然只有值 0,1,2,3
【问题讨论】:
-
a[i] = (a[i]*count);是做什么的?