I need help
I'm using Eclipse and right now I'm just totally lost as to what to do. I don't even know where to start.
Write a Java app that takes an int via a command-line argument args and passes it to the static method toBinaryString(int) of the Integer class. Have your app output the returned string. Assume, as a precondition, that args parses to an int without exceptions.
The only thing I have down is a method name :(, i need a little help with explanations please!
usually whenever a question asks that the app needs to function via a command line argument.
Originally Posted by Bungkai
try using the string array you pass in your main method.
public static void main(String args). the args.since the method need to take an int. parse the string into an integer and use in the static method for example.
I am not exactly sure of this method. i used to do this when i was using c. I am pretty new to java. Atleast its a heads up. Check it out
public static void main(String args)
int x= parse the args into an int.
First off, you have to know how to send arguments via Eclipse. To do so, check this out: How To Use Command Line Arguments in Eclipse
Next, you have to parse the argument into an integer. To do so, use the static method in the Integer class called "parseInt(String s)" Then use the static method in the Integer class (like you mentioned in your first post) called "toBinaryString(int i)". All of this can be found at Integer (Java 2 Platform SE 5.0)
so for example:
int x = Integer.parseInt("52");
//convert a String object to an Integer object which converts it to an int primitive data.
In my client code I have
Originally Posted by Lil_Aziz1
Binary is the name I have chosen as the variable, and by just using that it works, but I do not think I'm doing this the right way. I believe I am supposed to actually make the method by myself and call it to parse the integer given.
The only thing I know to go about doing that is that it probably involves recursion because of the 1s and 0s, any other advice to go along doing this?
Edit:Sorry, not recursion, don't know what I was thinking, but, I still do need a little help!