我是 java 的新手,我正在尝试创建一个简单的 java 程序来检查算术和几何序列,并从序列中列出所需数量的项。程序中的所有内容都正常工作,直到打印 for 语句中的下一项。没有错误,我也找不到任何错误。感谢您的帮助。
if(num2-num1 == num3-num2){
d = num2-num1;
System.out.println("This is a arithmetic sequence.\nCommon Difference = " + d);
System.out.println("How many terms of this sequence would you like?");
int a = scanner.nextInt();
for(int i = 1; i >= a; i++){
num3 += d;
System.out.println(num3);
}
suc = 1;
}
最佳答案
请更改i>=a
至 i<=a
.
关于java - 在 for 语句中打印解决方案时出现未知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18863586/