如果循环,则为2的幂 [英] Power of 2 if loop

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

问题描述

尝试这样做:

使用FOR循环,从1到50显示2的幂。   (2到1的功率到2到50的功率)。使用长变量来存储结果。示例:2到4的幂是2 x 2 x 2 x 2. 

Using a FOR loop, display the powers of 2 from 1 to 50.   (2 to the 1st power through 2 to the 50th power). Use a long variable to store your results. Example: 2 to the 4th power is 2 x 2 x 2 x 2. 

我见过有人使用Math.pow ()但我不知道如何插入这里,因为我没有要求用户提供任何输入。 

I've seen people using the Math.pow() but I don't know how it would work being plugged in here as I'm not asking a user to provide any input. 

仅供参考我这是我编程的第二周所以请保持简单。请

FYI this is my second week in programming so keep it simple, please. 

推荐答案

将长整数设置为1 。

Set a long integer to 1.

写一个执行50次的'for'循环。每次循环,将你的整数乘以2并显示结果。

Write a 'for' loop that executes 50 times. Each time through the loop, multiply your integer by 2 and display the result.

我们不应该在这个论坛上做家庭作业,所以这和我能告诉你的一样多。如果你遇到困难,我们可以(可能)帮助你解决代码中的特定问题。

We are not supposed to do homework assignments on this forum, so that's about as much as I can tell you. Have a go, and if you get stuck we can (might) help with specific problems in your code.


这篇关于如果循环,则为2的幂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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