The problem is... there is no formatting data in an int. It doesn't have any concept of leading zeros, etc. So, when you print out the int, you have to add the format back, which includes adding any leading zeros.
Just tried nextLine(); and get an error type missmatch, cannot convert from string to int.
I think the suggestion was to use a string instead of an int. This way, the formatting is retained, and you can print out the leading zeros. If you convert the string to an int, then you are back to your original problem, you lost any formatting data.
And BTW, you do know that in your example, your radix is 10 right? So, when 10101010 is read as an int, it is stored as 10 million, one hundred and one thousand, and ten ? And not stored as 170 (decimal equiv, I think) ?
Yes I know the number as an int is 10million plus. I don't want the number as an int I want each individual 1 or 0 to be an index of the array. I guess maybe my issue is initialing the array with the user input, maybe there is a better way?
I see what you are saying Henry, so when I use my code the first a[i] is = to the number I type in. , and doesnt actually index each individual number as a 0 or 1. now How do I overcome that issue?
That is a method for displaying an or of two binary numbers.(at least i think) I am trying to read in two binary numbers each 1 byte long, and then use that method to output their or.
edit: OK I got the initialization to work if I prompt the user to add a space, using nextInt(); so 0 1 0 1 1 1 1 1 will display as that when returned. A little bit unorthodox for the user, but I cant come up with a better solution atm.
Having come late to the discussion, I am a bit behind things, but your last method won't work.
You are creating a new array, then iterating through it, then returning a number, which will be the last number in the array.
A new int array is filled with 0s by default, so that method will always return a 0.
Go through the Integer class, and you find methods which will return their binary/octal/hexadecimal representation, but always without leading 0s.
posted 11 years ago
Thanks all for the wonderful help. After much thought I figured I wouldnt be able to use an int array to do what i needed to do. At least not with my current knowledge of Java, or any programming language atm.
I have changed to this current code and for the or method it is working.
The converting to and from char to string then back again seems a bit cumbersome, but until I can figure out a better way this works.
I still have one issue, and that is being able to tell if a 1 or 0 is being used exclusively from the user. I am on to that bit now.
Again thanks all
Their achilles heel is the noogie! Give them noogies tiny ad!
Devious Experiments for a Truly Passive Greenhouse!