Results 1 to 4 of 4

Thread: I need help

  1. #1
    Bungkai is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default 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[0] 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[0] parses to an int without exceptions.


    The only thing I have down is a method name :(, i need a little help with explanations please!

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    Quote Originally Posted by Bungkai View Post
    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[0] 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[0] 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.

    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.

    Java Code:
    public static void main(String args[])
    {
      int x= parse the args[0]  into an int.
      method(x);
    }
    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

  3. #3
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    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:
    Java Code:
    int x = Integer.parseInt("52");
    //convert a String object to an Integer object which converts it to an int primitive data.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  4. #4
    Bungkai is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by Lil_Aziz1 View Post
    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:
    Java Code:
    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
    "System.out.println(Integer.toBinaryString(Binary) );"

    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!
    Last edited by Bungkai; 01-13-2010 at 09:12 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •