以起始编号= 13,上限= 112,step_size = 3运行程序 只要数字继续打印数字
我已尝试将其拆分并使用break失败完成此任务。
public class Bounds {
public static void main(String[] args) {
int startingNumber;
int upperBound = 112;
int stepSize =3;
int count =0;
Scanner input = new Scanner(System.in);
System.out.println("Enter starting number: ");
startingNumber=input.nextInt();
System.out.println("Enter upper bound number");
upperBound = input.nextInt();
System.out.print(startingNumber + " ");
System.out.print(" ");
while (startingNumber <= upperBound) {
System.out.print((startingNumber += stepSize) + " ");
if ((count%10) == 0)
count += 3;
System.out.print( " ");
input.close();
}
}
}
答案 0 :(得分:0)
太复杂了,使用for循环怎么办
public static void main(String[] args) {
int startingNumber;
int upperBound = 112;
int stepSize =3;
int count =0;
Scanner input = new Scanner(System.in);
System.out.println("Enter starting number: ");
startingNumber = input.nextInt();
System.out.println("Enter upper bound number");
upperBound = input.nextInt();
int range = upperBound - startingNumber;
for (int i = startingNumber; i < upperBound; i+=stepSize) {
System.out.println(i);
count++;
}
System.out.println("done: count value: "+count);
}
答案 1 :(得分:0)
您对以下内容有什么想法?
if ((count%10) == 0)
count += 3;
因此,仅在余数为零时才递增计数。那只会工作一次。但是您还要采取什么其他措施?也许您是想做这样的事情。
count += 3;
if ((count%10 == 0) {
System.out.println();
}