如一数组{10,20,30,40,50,60,70},我输入一个比较符号和一数字,如符号:">",数字:"39",则能将>39的所有数字均查出,请问这个正则怎样写?

解决方案 »

  1.   

    怎么可能没关系呢?现在一段程序里面只能用正则,不能用简单的比较符号(如>,<,>=...)来比较数字大小(当然也有可能是字符或是汉字其它的),如题所示我如果输入 >= 39,则判定出来的40,50,60,70都符合要求。我就是要达到这个效果。
      

  2.   

    把输入的表达式转化一下就可以了,楼主可以写个转化的方法,用
    if(">".equals(str)){
      //用>号比较
    }
      

  3.   


    public static void test(String str, int a) {
    int b[] = {10,20,30,40,50,60,70};
    if (str != null && str != "") {
    if (str.equals(">")) {
    int i = 0;
    for (int d : b) {
    if (d > a) {
    System.out.println(d);
    }
    }
    }
    }
    }
    public static void main(String[] args) {
    test(">", 40);
    }