简体   繁体   English

数组循环如何对其自身进行三倍计时

[英]Array loop how to times itself three times

I am new to java, and I am trying to make the below array to make it times itself three times. 我是java的新手,我正在尝试制作以下数组,使其自身倍增3倍。 The output is currently the same. 当前输出是相同的。 How do I make it so it makes the output: let's say input i=1 and output will be {3,6,12} so it times the number before that three times. 我如何使它成为输出:假设输入i = 1,输出将为{3,6,12},因此将其乘以该数字之前的三倍。

double [] conversion = new double [3];
for(int i=0;i<conversion.length;i++){
    conversion[i]=3*bytes;
double [] conversion = new double [3];
for(int i=0;i<conversion.length;i++){
    conversion[i]=3*i;

But where comes bytes form, why do you use it 但是字节形式在哪里,为什么要使用它

You'd want to set the first value in the array to 3x your input, and then just loop through the values after that. 您希望将数组中的第一个值设置为输入的3倍,然后在其后循环遍历这些值。

int inputNumber = 1;
int[] conversion = new int[3];
conversion[0] = inputNumber * 3;
for(int i = 1; i < conversion.length; i++) {
    conversion[i] = conversion[i-1] * 3;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM