【发布时间】:2015-03-26 19:12:10
【问题描述】:
大家好,这是我的检查方法,但我无法处理逻辑。 姓名工作正常,但年龄 \ 体重 \ 身高工作方式错误(当我期待为真时,它变为假)。
我已经用 more () 尝试了几次,但我仍然无法修复它。请帮助我解决这个逻辑,或者如果您有更好的想法来检查并显示有关文本视图中错误值的消息。 Atm 我正在尝试使用警报生成器。
当我输入:_Age 24 时,if 语句加 10(当它低于 9 且超过 70 或为空时,我想加 10) 其余变量也是如此,我找不到我的逻辑错误。
private String checkValue(){
String x = "";
int a = 0; // TRUE == 1 false == 0 NAME > AGE > HEIGHT > WEIGHT
String name = textName.getText().toString();
String _Age = textAge.getText().toString();
String _Weight = textWeight.getText().toString();
String _Height = textHeight.getText().toString();
if ( TextUtils.isEmpty(name)) a+=1;
if ( TextUtils.isEmpty(_Age) || ((Integer.parseInt(_Age) > 9) && (Integer.parseInt(_Age) < 70 ))) a+=10;
if ( TextUtils.isEmpty(_Height) || ((Integer.parseInt(_Height) > 100) &&( Integer.parseInt(_Height) < 250))) a+=100;
if ( TextUtils.isEmpty(_Weight) || (( Double.parseDouble(_Weight) > 30 ) && (Double.parseDouble(_Weight) < 300))) a+=1000;
if (a==0) x="All right boss here's the answer for your awsome body";
while (a>=1) {
x += "Please fill the data: otherwise - I cannot help you out mate";
if (a >= 1000){
x += ("\n- Weight a= "+a+" parse int _Weight: " + Integer.parseInt(_Weight));
a-=1000;
}
if (a >= 100){
x += ("\n- Height a= "+a+" parse int _Height: " + Integer.parseInt(_Height));
a-=100;
}
if (a >= 10){
x += ("\n- Age a= "+a+" parse int _Age: " + Integer.parseInt(_Age));
a-=10;
}
if (a >= 1) {
x += "\n- Name";
a -=1;
}
}
【问题讨论】:
-
你能把具体问题说得更清楚一点,也许格式再多一点吗?您有一些变量悬而未决,看起来它们即将从悬崖上掉下来。