String SYHC = rs1.getString("syhs");
if(SYHC=="0" ||  SYHC=="1" ||  SYHC=="2" ||  SYHC=="3" ||  SYHC=="4" ||  SYHC=="5" ||  SYHC=="6" ||  SYHC=="7" ||  SYHC=="8" ||  SYHC=="9"){ 
         .........
         .........
  }
如上面所写。我想判断SYHC是否是0~9之间的数。有没有更简单的方法?求指教。

解决方案 »

  1.   

    如果syhs字段中保存的是字符串:
    if(SYHC.length==1&&SYHC.compareTo("0")>=0&&SYHC.compareTo("9")<=0)如果syhs字段中保存的是数字:
    double SYHC = rs1.getDouble("syhs");
    if(SYHC>=0&&SYHC<=0)
      

  2.   

    String s = "^[0-9]$";
    Pattern pattern = Pattern.compile(s);
    Matcher m = pattern.matcher("syhs");
                    boolean b = m.find();//判断是否匹配
      

  3.   

    String SYHC = "0";
    String num="1234567890";
    if(num.contains(SYHC)){
        System.out.println("SYHC is num~!");
    }
      

  4.   

    String SYHC = "8";//0-9
    String s = "^[0-9]$";
    Pattern pattern = Pattern.compile(s);
    Matcher matcher = pattern.matcher(SYHC);

    while (matcher.find()) {
    System.out.println(matcher.group());
    System.out.println("包含");
    }