Effective numbers by comma into the mass



  • How do we operate the chemical numbers of the line divided by the comma?

    I have a code for whole numbers without dividers. I need to adapt it to the actual numbers, or get advice on how to process them.

    The code is designed to search for the least sequence.

    Introduction of adapted code - -4.44,-5.525,-2.30,1,-2.01,-2.363,44.5,-2.344,-2.344,-2.3,-4.35

    Conclusion -2.01,-2.363 (this is the shortest)

    If the lines of the same length are found, a large amount is chosen.

        public static int getMinimumValue(String inValue){
        boolean minusTrigger = false;//фильтр
        StringBuilder buffer = new StringBuilder();
        System.out.println("Входные значения : " + inValue);
        for (int i = 0; i < inValue.length(); i++){
            switch (inValue.charAt(i)){
                case '-':
                    minusTrigger = true;
                    break;
                case '0':
                    minusTrigger = false;
                    //проверка на вставку 0
                    if (buffer.length() > 0 &&
                            buffer.charAt(buffer.length() - 1) != '0'){
                        buffer.append('0');
                    }
                    break;
            }
            if (!minusTrigger && inValue.charAt(i) >= 49 && inValue.charAt(i) <= 57){
                buffer.append(inValue.charAt(i));
            }
        }
        System.out.println("Значения после фильтра : " + buffer);
    
    String[] arrayValues = buffer.toString().split("0");
    
    try {
        int minValue = Integer.MAX_VALUE;
        for(String value: arrayValues){
            int intBuffer = Integer.parseInt(value);
            minValue = intBuffer &lt; minValue ? intBuffer : minValue;
        }
        return minValue;
    }
    catch(Exception x){
        System.out.println("Невозможно найти значения больше 0");
        return -1;
    }
    

    }



  • If you mean,

    -4.44,-5.525,-2.30,1,-2.01,-2.363,44.5,-2.344,-2.344,-4.35

    Transform into a type of mass StringI mean, it's like,

    String[] arr = "-4.44,-5.525,-2.30,1,-2.01,-2.363,44.5,-2.344,-2.3,-4.35".split(",");
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2