Java 数字模式中断
我试图弄明白为什么这段代码在8之后不会显示任何内容Java 数字模式中断,java,numbers,Java,Numbers,我试图弄明白为什么这段代码在8之后不会显示任何内容 public class numGame { public static void main(String[] args) { int number1 = 3; int number2 = 8; int total = 0; System.out.print(number1 + " ");
public class numGame
{
public static void main(String[] args)
{
int number1 = 3;
int number2 = 8;
int total = 0;
System.out.print(number1 + " ");
System.out.print(number2 + " ");
while (total <450)
{
total = number1 + number2;
System.out.print(total + " ");
number1 = number2;
number2 = total;
}
}
}
公共类numGame
{
公共静态void main(字符串[]args)
{
整数1=3;
整数2=8;
int-total=0;
系统输出打印(数字1+“”);
系统输出打印(数字2+“”);
而(总计这甚至不会编译
a) 总和没有定义
b) 您打印出总计,但该值仅设置为0
c) num1和num2都不递增,所以总和总是相同的值(无止境的while循环)
d) 未定义num1或num2
e) 为什么要在最后更改number1和number2的值
试一试
while(总计<450){
总数=1号+2号;
编号1=编号2;
数字2=总数;
}
您没有在任何地方计算总计
总和和总数令人困惑
同样,num1和number1也令人困惑
而循环应该有花括号
while (total < 450) {
total = number1 + number2;
number1 = number2;
number2 = total;
}