检查值是否在一系列数字之间

时间:2015-12-04 10:47:38

标签: java android integer compare

我正在尝试检查文本框中的值是否在4到80之间,但是不能 我能做到这一点,但它不是我需要的

 final String checkage = age.getText().toString();
    if(checkage.equals(4)   || checkage.equals(80) ) {
        Toast.makeText(this, "You must be older than 4 and younger than 80", Toast.LENGTH_SHORT).show();
        return;
}

2 个答案:

答案 0 :(得分:5)

使用此:

final String checkage = age.getText().toString();
int value = Integer.parseInt(checkage);

if(value >= 4 && value <= 80) {
      Toast.makeText(this, "You must be older than 4 and younger than 80", Toast.LENGTH_SHORT).show();
      return;
}
在这种情况下,

' || '对您没用。

答案 1 :(得分:0)

你的逻辑错了。你需要做这样的事情。

======================================================================
ERROR: test_changing_credentials (base.tests.test_base.BaseTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.7/unittest/case.py", line 329, in run testMethod()
File "/pipeline/source/django/base/tests/test_base.py", line 99, in   test_changing_credentials
driver.wait_for_css("h4#change-credentials-header").click()
File "/pipeline/source/django/libs/webdriver.py", line 45, in wait_for_css
raise TimeoutException(css_selector)
TimeoutException: Message: h4#change-credentials-header
相关问题