I’m trying to convert Strings of user input into int. No problem with that, i’m using the following code:
c = sc.next();
while(!c.contains("#")){
i = Integer.parseInt(c);
input.add(c);
c= sc.next();
}
(this is just the part of the code that does the conversion, the scanner part is working)
The only problem is that the input are binary numbers, so when the input is, for example “00111”, the convert gives me “111” and i can’t lose those 0’s. How can i convert the user input into the number without losing the zeros to the left?
If
00111is different from111then you can’t store it as integers, you’ll need to store them as strings.Note however, that even in binary, 001112 is equal to 1112.
To parse a binary literal and store it in an integer, you use
(but this doesn’t solve the problem of keeping the leading zeros.)