安卓 Java If/Else语句决策
我真的很困惑如何在Android Java中构造这些语句的if/else
场景
我的客户欠了n美元的债
我的客户想还钱,我允许他/她用比特支付
这就是问题所在
Min Payment是$500,这意味着你不能低于$500支付,而Min Payment应该是$500,这意味着如果你有$900你不能支付$400或$500你必须准确支付900。所以,这就是我所做的
if (inputVal < 500 || inputVal > main) {
if (inputVal < 500) {
amount_to_pay.setError("Min Charge: 500");
pay_of_loan.setEnabled(false);
}
if (inputVal > main) {
amount_to_pay.setError("Max Charge: " + ccNum);
pay_of_loan.setEnabled(false);
}
} else {
amount_to_pay.setError(null);
pay_of_loan.setEnabled(true);
}
当按钮通过上面的if/else
时,该按钮被启用
if (inputVal - main < 500 && inputVal != main) {
Toast.makeText(getActivity(), "Please choose between ₦ " + ccNum + " and ₦ " + String.valueOf(main - 500), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "We are good to go", Toast.LENGTH_SHORT).show();
}
但是,它永远无法验证。在逻辑方面的任何帮助都将不胜感激。谢谢
# 1 楼答案
假设:
计算输入是否有效
如果输入等于支付总额,则验证
否则:如果输入大于或等于最小值(500),剩余值(主要输入)大于或等于500,且输入小于最大值(主要输入),则输入有效
你把它用作:
以及:
# 2 楼答案
试试这个
到
为了
到