import java.io.*;
import java.util.regex.*;
class CheckDigit
{
public boolean check(String str)
{
if(str.matches("\\d+"))
{
return true;
}
else
{
System.err.println("必须是数字!请重新输入");
return false;
}
}
}
class InputData
{
BufferedReader br =null;
String success=null;
String tips=null;
String str = null;
public InputData(String tips,String success)
{
br=new BufferedReader(new InputStreamReader(System.in));
this.success=success;
this.tips=tips;
}
public String getStr()
{
System.out.println(tips);
try{
str=br.readLine();
}catch(Exception e)
{
e.printStackTrace();
}
return str;
}
public Integer getInteger()
{
System.out.println(success);
return Integer.parseInt(str);
}
}
public class override
{
public static void main(String args[])
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int i=0;
int j=0;
boolean flag=true;
CheckDigit cd = new CheckDigit();
InputData id1 = new InputData("请输入第一个数字","输入成功!");
while(flag)
{
if(cd.check(id1.getStr()))
{
i=id1.getInteger();
flag =false;
}
}
InputData id2 = new InputData("请输入第二个数字","输入成功!");
if(cd.check(id2.getStr()))
{
j=id2.getInteger();
}
System.out.println(i+"+"+j+"="+(i+j));
}
}
要求:通过键盘输入数据完成加法操作