我有一个for循环,调用它的方法是printMe(),我希望用户能够确定使用他们的输入运行多少次。这符合我的想法:
System.out.println("Enter a number: ");
loop = input.nextInt();
最佳答案
这应该工作:
Scanner input = new Scanner(System.in);
int loop = input.nextInt();
for(int i = 0; i<loop;i++){
//do the thing
}