一段连续的数字,比如3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25如何让结果变成3,5,6,7,8,9,10,11,12,13,15,16,17,18,19,20,21,22,23,25即将带4的数字排除掉!

解决方案 »

  1.   


     public class Hello { /**
     * @param args
     */
    public static void main(String[] args) {
    List list1= new ArrayList();
       List list = new ArrayList();
       for(int i = 0; i<30;i++){
      list.add(i); 
       }
       for(int i = 0;i< list.size();i++){
       if(!list.get(i).toString().endsWith("4")){
       list1.add(list.get(i));
       }   
       }
       for(int j=0;j<list1.size();j++){
       System.out.println(list1.get(j));
       }
    }
    }  你参考下
      

  2.   


    public static void main(String[] args) {
    int testArray[] = new int[] { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };
    StringBuffer result = new StringBuffer();
    for (int i = 0; i < testArray.length; i++) {
    int b = testArray[i];
    int c = 0;
    int sum = 0;
    while (b > 0) {
    c = b % 10;
    if (c == 4) {
    sum++;
    break;
    }
    b /= 10;
    }
    if (sum == 0) {
    if (i == testArray.length - 1) {
    result.append(testArray[i]);
    } else {
    result.append(testArray[i]).append(",");
    }
    }
    }
    System.out.println(result.toString());
    }
      

  3.   

    String str="3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 ";
    String str1=str.replaceAll("4","");
      

  4.   


    public static void main(String[] args) {
    String test = "3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 ";
    String s [] = test.split(",");
    for (int i = 0; i < s.length; i++) {
    if (s[i].indexOf("4") == -1) {
    System.out.println(s[i]);
    }
    }
    }
      

  5.   

    String s = "3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25";
    s = s.replaceAll("(,\\d*[4])", "");
      

  6.   

    String str = "3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 ";
    Pattern pattern = Pattern
    .compile("[0-9]*4[0-9]*,");
    Matcher isNum = pattern.matcher(str);
    str = isNum.replaceAll(str);
      

  7.   

    只要带4就删啊, 重新更正一下
    String s = "3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,49,141";
    s = s.replaceAll("(,\\d*4\\d*)", "");
      

  8.   


    import java.util.ArrayList;
    import java.util.List;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Regex {
    public static void main(String[] args) {
    String s = "3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25";
    List<String> list = getStrings(s);
    for(String sl:list){
    System.out.println(sl+"---");
    }
    } public static List<String> getStrings(String s) {
    List<String> list = new ArrayList<String>();
    String[] start = s.split(",");
    /*String regex = "[4]";
    Pattern p = Pattern.compile(regex);*/
    for (int i = 0; i < start.length; i++) {
    //是否包含4
    if(!start[i].contains("4")){
    list.add(start[i]);
    }
    }
    return list;
    }
    }
      

  9.   


            int[] arr = {3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
            int[] temp = new int[arr.length];
            int j =0;
            for(int i = 0; i< arr.length;i++) {
                if(String.valueOf(arr[i]).indexOf("4") == -1) {
                    temp[j] = arr[i];
                    j++;
                }
            }
            int[] result = new int[j];
            for(int k = 0; k < j; k++) {
                result[k] = temp[k];
                System.out.print(result[k] +  " ");
            }
      

  10.   


            public static void deleteElement(int[] N,int K) {
    List<Integer> list = new ArrayList<Integer>();
    for(int a : N) {
    String str = String.valueOf(a);
    if(str.contains(String.valueOf(K)))
    continue;
    list.add(Integer.valueOf(str));
    }
    }
      

  11.   

    Pattern p;
    Matcher m;
    String str="3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 ";
    p=Pattern.compile("\\d{1,}";
    m=p.matcher(str);
    while(m.find()){
        System.out.print(m.group()+",");
    }上面哪个错了。这个可以满足要求。
      

  12.   

    用循环效率上是不是有问题,String类本身不是有contains方法么
      

  13.   

    public class Test5 {
        
        public static void main(String[] args) {
            String str = "4,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,34";
            str = str.replaceAll("\\d*4\\d*,?|,?\\d*4\\d*", "");
            System.out.println(str);
        }
    }
      

  14.   


    import java.util.*;public class Test { public static void main(String[] args) {
    String str = null;
    List list = new ArrayList();
    String[] str1 = new String[50];
    Scanner sc = new Scanner(System.in);
    str = sc.nextLine();
    str1 = str.split(" ");
    for (int i = 0; i < str1.length; i++) {
    if (str1[i].indexOf("4") < 0) {
    list.add(str1[i]);
    }
    }
    for (int i = 0; i < list.size(); i++) {
    System.out.println(list.get(i));
    }
    }
    }