使用第二个变量打印1到n的数字
我是这样写的
System.out.println("enter the input number");
int input = sc.nextInt();
Run Code Online (Sandbox Code Playgroud)
输入一个变量,但我们再次使用另一个变量.所以我堆在这里.
如果我这样写,它显示1到整数的最大值,但在这里我没有输入值
for(int i=1;i<Integer.MAX_VALUE;i++)
{
System.out.println(i);
}
Run Code Online (Sandbox Code Playgroud)
如果我像这样写我带两个变量
for(int i=1;i<input;i++)
{
System.out.println(i);
}
Run Code Online (Sandbox Code Playgroud)
但我只显示最大值的整数,但我想显示最多n个数字,即我给出的输入数字