我正在编写的这段代码有问题。代码的目的是为数字序列制定修饰符,然后给出该序列中的前 10 个数字。但是,我的循环机制似乎有问题,因为它在应该只执行 10 时打印出无限数量的值。我计划在代码中包含除法和幂函数,但遇到了这个问题。
import java.util.Scanner;
public class PatternCreator {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out
.println("Please enter the starting value of the number sequence.");
double sequence = s.nextInt();
System.out
.println("Please enter the addition/subtraction modifier; e.g. 2,-2.");
double addsub = s.nextInt();
System.out
.println("Please enter the multiplication modifier; 0 for none.");
double mult = s.nextInt();
System.out.println("Please enter the division modifier; 0 for none.");
double divi = s.nextInt();
System.out
.println("Please enter the exponential modifier; 0 for none.");
double power = s.nextInt();
double addonly = sequence + addsub;
while (mult == 0 && divi == 0 && power == 0) {
for (int count1 = 1; count1 <= 10; count1++) {
if (count1 == 1) {
System.out.print(sequence + " ");
} else {
System.out.print(addonly + " ");
addonly = addonly + addsub;
}
}
}
double multadd = sequence + addsub * mult;
while (mult != 0 && divi == 0 && power == 0) {
for (int count2 = 1; count2 <= 10; count2++) {
if (count2 == 1) {
System.out.print(sequence + " ");
} else {
System.out.print(multadd + " ");
multadd += multadd;
}
}
}
}
}