I have this code that takes input from a textbox and does this
if user inserts number 12 the program must print 0000000...(until 30 0)12 this is my code
String zero = "00000000000000000000000000000000";
getnumber = zero.substring(0, 32 - getnumber.length()) getnumber;
the code works fine until i insert only one number example 3 it will crash. Any idea why this happens?
CodePudding user response:
You must put -1 to the length.
String zero = "00000000000000000000000000000000";
getnumber = zero.substring(0, 32 - getnumber.length()-1) getnumber;
This worked for me.
CodePudding user response:
Seems to me that you are trying to pad the number with zeroes. If that's the case, I highly suggest you check out this answer and use functions that are already a part of the language instead of reinventing them.