import javax.swing.JOptionPane;
public class Jt {
public static void main(String[] args) {
int nCases=0,Heads=0,Feet=0,Rabbits=0,Chicken=0;
boolean contiGo=true;
String numString=JOptionPane.showInputDialog("请输入测试数据组数的整数:");
try{
nCases=Integer.parseInt(numString);
if(0>=nCases){
JOptionPane.showInputDialog(null,"测试次数<=0,系统退出。","结果",JOptionPane.QUESTION_MESSAGE);
System.exit(0);
}
}catch(Exception ne){
JOptionPane.showInputDialog(null,"输入的不是数据,不符合规定,系统退出。","结果",JOptionPane.QUESTION_MESSAGE);
System.exit(0);
}
for(int k=0;k<nCases;k++){
while(contiGo==true){
numString=JOptionPane.showInputDialog(null,"请输入鸡和兔子头的个数(整数):","输入提示",JOptionPane.QUESTION_MESSAGE);
try{
Heads=Integer.parseInt(numString);
if(0>=Heads)
JOptionPane.showInputDialog(null,"头的个数不能是0或负数,请重新输入");
else
break;
}catch(NumberFormatException ne){
JOptionPane.showInputDialog(null,"输入的数据类型有误,请重新输入");
}
}
while(contiGo==true){
numString=JOptionPane.showInputDialog(null,"请输入鸡和兔子头的个数(整数):","输入提示",JOptionPane.QUESTION_MESSAGE);
try{
Feet=Integer.parseInt(numString);
if(Feet%2!=0)
JOptionPane.showInputDialog(null,"脚的总数为单数,这是不行的。","报错",JOptionPane.QUESTION_MESSAGE);
else if(0>=Feet)
JOptionPane.showInputDialog(null,"脚的个数不能是0或负数,请重新输入");
else if(Feet>(4*(Heads-1)+2)||(4+2*(Heads-1))>Feet)
JOptionPane.showInputDialog(null,"脚的个数太多或太少,与头的个数不匹配,请重新输入");
else
break;
}catch(NumberFormatException ne){
JOptionPane.showInputDialog(null,"输入的数据类型有误,请重新输入");
}
}
Chicken=2*Heads-Feet/2;
Rabbits=Heads-Chicken;
JOptionPane.showInputDialog(null,"有"+Rabbits+"只兔子,\n有"+Chicken+"只鸡。","计算结果",JOptionPane.QUESTION_MESSAGE);
}
}
}