您的位置:首页 > 运维架构

JOptionpane.showinputdialog 数据异常 处理

2009-01-12 20:12 471 查看
first=JOptionPane.showInputDialog( "请输入第1条边长: ");
second=JOptionPane.showInputDialog( "请输入第2条边长: ");
third=JOptionPane.showInputDialog( "请输入第3条边长: ");

n1=Integer.parseInt(first);
n2=Integer.parseInt(second);
n3=Integer.parseInt(third);
添加异常处理,确保输入的数据不为空,并且都是正数?
try{
n1=Integer.parseInt(first);
n2=Integer.parseInt(second);
n3=Integer.parseInt(third);
}catch(NumberFormatException e){
System.out.println( "输入含有非数字符号!!!! ");
}

if(n1 <=0)
{
//为非正数
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐