英文:
how do i print numbers between i and b without including i
问题
如果第一个数字是6,第二个数字是16,那么它会打印出6,7,8,9,10,11,12,13,14,15;
。
我不希望打印出“6”,我应该添加什么语句?因为我不想将它们放入数组中,想要移除这个6并重新发送它。
System.out.println("输入一个数字:");
int i = input.nextInt();
System.out.println("输入另一个数字:");
int b = input.nextInt();
while (i >= 0 && i < b)
System.out.println(++i);
英文:
If the first number is 6 and the second one is 16, it prints 6,7,8,9,10,11,12,13,14,15;
I dont want the "6" to be printed, what statement should I add because I don't want to put them in an array, remove the 6 and resend it
System.out.println("enter a number : ");
int i = input.nextInt();
System.out.println("enter another number : ");
int b = input.nextInt();
while (i >= 0 && i<b)
System.out.println(i++);
答案1
得分: 2
使用for循环
如下所示:
System.out.println("请输入一个数字:");
int i = input.nextInt();
System.out.println("请输入另一个数字:");
int b = input.nextInt();
for (int j = i + 1; j <= b; j++) {
System.out.println(j);
}
当您输入1 16
时,它会产生:
6
7
8
9
10
11
12
13
14
15
英文:
Use a for loop
like so:
System.out.println("enter a number : ");
int i = input.nextInt();
System.out.println("enter another number : ");
int b = input.nextInt();
for(int j = i+1; j <= b; j++){
System.out.println(j);
}
When you input 1 16
it produces:
6
7
8
9
10
11
12
13
14
15
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论