How to operate with real numbers from a string separated by commas?
I have a code for integers, without delimiters (Example 241-3234-2340-35011110-3). I need to adapt it for real numbers, or get advice on how to handle them.
The code is designed to find the smallest subsequence.
Input of the adapted code - -4.44, -5.525, -2.30,1, -2.01, -2.363,44.5, -2.344, -2.3, -4.35
Conclusion - -2.01, -2.363 (it is the shortest shopping mall)
If there are substrings of the same length, then a large sum 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 < minValue ? intBuffer : minValue; } return minValue; } catch(Exception x){ System.out.println("Невозможно найти значения больше 0"); return -1; } }