我的小程序有点问题.我有一个JOptionPane要求一个数字,如果这个数字小于10,那么一个循环只会持续不断地做其中的内容,继续询问数字.在该循环中,我调用一个方法,使用int作为参数.在该方法中,我需要(不改变调用该方法的类中的任何代码)找出我输入的数字是否小于1.如果是,我需要调用另一种方法.那一点完成了.
但!mainloop不断滚动,所以它继续在循环中执行其他操作.我需要阻止它这样做,所以在方法的if语句中我需要打破方法所在的循环的特定迭代,并使其继续进行同一循环的新迭代,要求新号码.
第一类(例子):
number=Integer.parseInt( JOptionPane.showInputDialog( "bla bla" ) );
while (number !=- 10) {
themethod(number);
blah
blah
...
}
Run Code Online (Sandbox Code Playgroud)
被调用的方法(例子):
public void themethod(int number) {
if (number<1) {
call the other method
break the iteration im in
}
Run Code Online (Sandbox Code Playgroud)