-5

I don't know almost nothing about java integers. I have an updater and i want the number 2.3.1 be smaller than 2.4. I'm trying this but no success:

private Integer versionLenghtCorrector(Integer version1, Integer version2) {
    for (String version = version1.toString(); version.length() < version2.toString().length(); version = version + "0") {
        return Integer.parseInt(version);
    }
    return 0;
}
private void start() {
// End of Update code.
        Integer uVersion = versionLenghtCorrector(Integer.parseInt(updateVersion.replaceAll("\\.", "")),
                Integer.parseInt(pluginVersion.replaceAll("\\.", "")));
        Integer pVersion = versionLenghtCorrector(Integer.parseInt(pluginVersion.replaceAll("\\.", "")),
                Integer.parseInt(updateVersion.replaceAll("\\.", "")));
        if (uVersion > pVersion) {
            this.checkResult = UpdateCheckResult.AVAILABLE;
        } else {
            this.checkResult = UpdateCheckResult.NOT_FOUND;
        }
}
  • 2
    Why `return Integer.parseInt(version);` is in `for` loop? – vinS Dec 16 '17 at 02:50
  • ooo sorry I'm a little noob in for loops, did not know that return could not stay there. – Christiano Rangel Dec 16 '17 at 02:57
  • If you want `2.3.1` to be smaller than `2.4` (and smaller than `2.11`), then you should implement your own `Comparator`. – Andreas Dec 16 '17 at 02:58
  • @ChristianoRangel `return` can stay there, but it returns immediately on the first iterated value, and will never continue the loop, so what's the *point* of the loop? – Andreas Dec 16 '17 at 02:59

1 Answers1

0
public static int addZeros(int valueToAddZeros, int valueToCompare){
    while(String.valueOf(valueToCompare).length() > String.valueOf(valueToAddZeros).length()){
        valueToAddZeros = valueToAddZeros * 10;
    }
    return valueToAddZeros;
}