如何在不包括 i 的情况下打印在 i 和 b 之间的数字。

huangapple go评论60阅读模式
英文:

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(&quot;enter a number : &quot;);
int i = input.nextInt();
System.out.println(&quot;enter another number : &quot;);
int b = input.nextInt();

while (i &gt;= 0 &amp;&amp; i&lt;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(&quot;enter a number : &quot;);
    int i = input.nextInt();
    System.out.println(&quot;enter another number : &quot;);
    int b = input.nextInt();

    for(int j = i+1; j &lt;= b; j++){
        System.out.println(j);
    }

When you input 1 16 it produces:

6
7
8
9
10
11
12
13
14
15

huangapple
  • 本文由 发表于 2020年10月6日 04:25:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/64215724.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定