![]() |
Decimal to binary help
I'm trying to code a program in java which converts decimal to binary but i keep getting this error upon compile:
Quote:
Quote:
Thanks |
Re: Decimal to binary help
Change your to this and try it out.
:
import java.util.Scanner; //this program uses class scannerDon't worry I'm not telling you off, just giving a few pointers. |
Re: Decimal to binary help
Also, your scanner had to be nextInt to get an integer from the user. You had a string wanting to be an integer and then a string a again.
|
Re: Decimal to binary help
Thanks for the tips. It works!
If i wanted to go about making this a recursive solution, how would i do it? |
Re: Decimal to binary help
You would have to make a class of it. For example:
:
public class Binary |
Re: Decimal to binary help
Sorry, I can't go into too much detail, too sleepy...:yawn:
|
Re: Decimal to binary help
This is what i have done so far...not working of course :(
Quote:
i get a compile error missing return statment line 9 |
Re: Decimal to binary help
You should use the return statement to return a string value from your method.
Let me know if this works. I didn't compile or test this code. :
public static String decToBin(int decimal, String str) |
Re: Decimal to binary help
Hey! Thanks for the reply. I tried using your code but it won't compile...just get "else without if on line9"..
The way you have done it isn't recursive though is it? i know my coding is horribly wrong for the conversion.. |
Re: Decimal to binary help
Quote:
As you can see from my snippet of code, I did indeed have an if statement. How did you insert my code in yours? Please just don't copy and paste. Understand and learn from what others are writing. It is frustating to hold your hand every step of the way. |
| All times are GMT -5. The time now is 4:11 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC