2个java代码的强大功能帮助我输入不同的结果
当我说给我2次幂的时候,它会打印出来2个java代码的强大功能帮助我输入不同的结果,java,Java,当我说给我2次幂的时候,它会打印出来 import java.util.Scanner; public class PowersOf2 { public static void main(String[] args) { int inputPowersOf2; int PowerOf2 = 1; int exponent; int exponent2; Scanner sca
import java.util.Scanner;
public class PowersOf2
{
public static void main(String[] args)
{
int inputPowersOf2;
int PowerOf2 = 1;
int exponent;
int exponent2;
Scanner scan = new Scanner(System.in);
System.out.println("How many powers of 2 would you like printed?");
inputPowersOf2 = scan.nextInt();
System.out.println("\n\n");
if(inputPowersOf2 >= 2)
{
System.out.println("Here are the first " + inputPowersOf2 + " powers of 2:");
System.out.println();
}
else
{
System.out.println("Here is the first power of 2:");
System.out.println();
}
exponent2 = 0;
exponent = 0;
while(exponent <= inputPowersOf2)
{
System.out.print("2^" + exponent2 + " = ");
exponent2++;
System.out.println((PowerOf2 = 2 * PowerOf2) / 2);
exponent++;
}
}
}
2^0
2^1
等等…替换
2^0
2^1
2^2
while(exponent您可以使用较小的输入在纸张上手动回溯步骤,然后继续进行较大的输入
只需替换代码即可(指数一步一步地通过代码。计算出每个变量的值。认为这是一个学习经历。问题是什么?为什么这是个问题?你试着做什么来解决这个问题?”JoeMcCay: + 1——这让我想起了我获得C学位的时候,第三年我和一个实验室合作伙伴,不仅从未学会过如何。使用调试器,但他甚至主动拒绝让我教他如何使用,因为他显然认为选择调试器是一种学习负担,他不会去处理。哎呀,别做那个家伙。调试器是你的朋友。你需要学习如何使用一个软件并找出它为什么不能满足你的需要的一般技能也是如此这是我必须做的。
while(exponent <= inputPowersOf2)
while(exponent < inputPowersOf2)