数组循环如何将自身计时三遍 [英] Array loop how to times itself three times

查看:63
本文介绍了数组循环如何将自身计时三遍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是java的新手,我正在尝试制作以下数组,使其自身倍增3倍。当前输出是相同的。如何使它成为输出:假设输入i = 1,输出将为{3,6,12},因此它乘以之前的数字三倍。

I am new to java, and I am trying to make the below array to make it times itself three times. 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.

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


推荐答案

您要在数组将输入的3倍,然后循环遍历之后的值。

You'd want to set the first value in the array to 3x your input, and then just loop through the values after that.

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;
}

这篇关于数组循环如何将自身计时三遍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆