我试图循环异常,但由于某种原因它不是给我的选项重新写我的扫描文件:循环永远
我不知道如何使用的BufferedReader所以这就是为什么我使用这个。任何线索?
这里是我的标准类和我的方法
package arrayExceptionsWithInput;
import java.util.*;
public class GetThoseNumbersBaby {
int firstInt;
int secondInt;
boolean error;
Scanner yourNumbers = new Scanner(System.in);
public void findNumbers()
{
System.out.println(" please enter your first number");
firstInt = yourNumbers.nextInt();
System.out.println(" pleas enter your second number");
secondInt = yourNumbers.nextInt();
int finalInt = (firstInt+secondInt);
System.out.println("total is: " + finalInt);
}
}
这是我的不同之处主要类与一环Implemeted一个:
package arrayExceptionsWithInput;
import java.util.*;
public class InputException
{
public static void main(String[] args)
{
boolean error = false;
GetThoseNumbersBaby zack = new GetThoseNumbersBaby();
{
do {
try
{
zack.findNumbers();
}
catch(InputMismatchException Q)
{
System.out.println(" one of your integers was incorrect, please try again");
Q.printStackTrace();
error = true;
}
} while (error == true);
}
error = false;
}
}
如果任何人有如何循环此不同的任何想法我都是耳朵。
你为什么要在{}内包裹do-while? – 2009-11-19 12:35:59
'while(error == true)' - >'while(error)' – JRL 2009-11-19 12:37:44
while(error == true)会更习惯性写入while(error) – Henry 2009-11-19 12:39:17