java - Calculate variable String(010) with integer(1) where outcome is string(011) -
the user can insert random string can contains numbers. must been possible calculate integer.
the problem user insert string 010 + integer(1) result in 11;
but want return string 011
but user can enter numbers 001, 0001, etc
what best approach here? have try use
string.format("%05d", yournumber); not work variable strings
i came across
string str = "abcd1234"; string[] part = str.split("(?<=\\d)(?=\\d)"); system.out.println(part[0]); system.out.println(part[1]);
if use got new problem. how split number in right way.
any idea i'm missing
considering handling integer number (not binary )
try this:
string input ="001";//your user input /** * check here if input number */ int len=input.length(); int inputinteger=integer.parseint(input); inputinteger+=1; string output=string.format("%0"+len+"d", inputinteger); system.out.println(output);
Comments
Post a Comment