对于涉及数学的循环 [英] For loop with math involved

查看:74
本文介绍了对于涉及数学的循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解决这个问题?它给我带来了很多麻烦!


Q.写一个使用for循环将你的体重乘以8倍的类,将金额存储在另一个变量中。

即在第一次迭代时,你的权重将被存储。在下一次迭代中,此数量将再次乘以您的体重并存储,依此类推。包括运行和测试应用程序的任何相关类。


提前致谢

Any ideas in how to do this question?? its causing me alot of trouble!

Q.Write a class that uses a for loop to multiply your weight by itself eight times, storing the amount in another variable.
i.e. on the first iteration your weight to the power of one will be stored. On the next iteration, this amount will again be multiplied by your weight and stored, and so on. Include any relevant classes to run and test the application.

Thanks in advance

推荐答案


如何解决这个问题?它给我带来了很多麻烦!


Q.写一个使用for循环将你的体重乘以8倍的类,将金额存储在另一个变量中。

即在第一次迭代时,你的权重将被存储。在下一次迭代中,此数量将再次乘以您的体重并存储,依此类推。包括运行和测试应用程序的任何相关类。


提前付款
Any ideas in how to do this question?? its causing me alot of trouble!

Q.Write a class that uses a for loop to multiply your weight by itself eight times, storing the amount in another variable.
i.e. on the first iteration your weight to the power of one will be stored. On the next iteration, this amount will again be multiplied by your weight and stored, and so on. Include any relevant classes to run and test the application.

Thanks in advance



...你做了什么到目前为止?

... and what have you done so far?



...到目前为止你做了什么?
... and what have you done so far?


展开 | 选择 | Wrap | 行号



code :( java)


公共类Project_1_3

{

public static void main(String [] args)

{


for(int i = 1; i< = 8; i ++)

{

int weight = 5;

System.out.println(" weight is" + Math.pow(weight,1.0));

}

}

}


i不知道如何存储变量,所以我可以再次使用它!
code: (java)

public class Project_1_3
{
public static void main(String[] args)
{

for(int i = 1; i <= 8; i++)
{
int weight=5;
System.out.println("weight is "+Math.pow(weight,1.0));
}
}
}

i dont know how to store the variable so i can use it again!!



我认为你需要移动int weight = 5;超出你的for循环和你的Math.pow行你需要使用你的虚拟变量i。每次递增指数。


I think you need to move "int weight = 5;" out of your for loop and in your Math.pow line you need to use your dummy variable of "i" to increment the exponent each time.


这篇关于对于涉及数学的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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