So I would say that line 7 and 10 should actually be in your main method and binary should be passed as a parameter to printBinaryFormat.
You will then need to declare an int array in your printBinaryFormat method, but you'll need to work out what size it needs to be somehow.
You might be better off just appending the digits to a StringBuilder - that way you don't need to know how long the binary value is going to be.
Here is the original from:
You already know how to get an int value from the Scanner object - I'm just saying you're doing it in the wrong place. If you do it in the main method you can then pass the value to the printBinaryFormat method.
In the original code (line 19), 25 is being passed to the method, so you just need to replace the 25 with the value you got from the Scanner.
If you leave the rest of the code as it was originally it will work.
Dan Good wrote:Like this?
Why have you put the  after the method name ?
I said to replace the 25 with the value returned from the Scanner.
You can either do this directly by replacing it with console.nextInt() or you can move line 7 of your original post into the main method and replace the 25 with the binary variable.
The printBinaryFormat method should not change at all from the code that you copied.
If none of this is making sense then you might want to take a look at this tutorial section on method parameters.
Dan Good wrote:Do you mind showing me? I feeling like I'm just gutting this and digging a deeper hole.
Which is why you need to read the tutorial I linked to.
There are examples in there of how to pass variable values to a method - if you can make use of those examples to work out how to fix your problem, you will have learnt a lot more than you will by me just giving you the answer.
This is one of the examples from the tutorial. It passes an int variable to a method that is declared to take a single int parameter - identical to what you are trying to do.
Ignore lines 11 - 13 and the contents of the called method for the moment - the only parts you are interested in are the passing of the parameter.
On line 3 it assigns a value to a variable - that is what you do on line 10 of your original post. You just need to move that line into the main method.
On line 9 it passes the variable as a parameter to the method.
I'm not deliberately being awkward - assigning values to variables and passing values to methods is something you will do a lot of when writing code, so it is better that you understand it now rather than just be given an answer and then have to ask the same question again the next time you come across something similar.
Dan Good wrote:Can you show me how to write those lines of code then?
I think you know the answer to that question.
The advice I have given you so far is
1. Return the content of the printBinaryFormat method to exactly how it was on the website you copied it from.
2. Line 10 from your original post needs to be moved into the main method.
3. Pass the binary variable to the printBinaryFormat method.
For the moment just do steps 1 and 2. It's just cutting and pasting. When you've done that post your new code.
Dan Good wrote:So like this?
Assuming it works then the only other change I would suggest is to make your console variable a non-static variable local to the main method. Although it won't be a problem in a simple program like this, you need to understand the difference between static and non-static variables, so you might want to study that at some point.
Dan Good wrote:How would I correct that? Please it's 0422 right now and I have to get some sleep at some point. I just need this done.
Assuming that's referring to my comments about your console variable in my first post, then, as I said, you don't need to for a simple program like this.
Dan Good wrote:Thank god. it works now. I both hate you and love you for sticking this out with me for the past 5 hours. You just got this Marine his next rank for bootcamp in 20 days. I needed to pass this last class so I could have enough credits to rank up for the summer. PFC.
Could I make a suggestion then? If you're a Marine, then you'll know that successful operations are almost always the result of good planning.
Programs don't just write themselves, they take thought - and lots of it.
So my advice: Next time, give yourself plenty of time; and if you DO run into problems, don't leave it to the last minute to ask for help.
Remember, we're all volunteers here.
You may also find the StopCoding (←click→) and WhatNotHow pages worth reading.