java equivalent function of c atoi() function

Discussion in 'Java' started by lonelyplanet999, Oct 22, 2003.

  1. Hi,

    I would like to ask any java standard library function behaves the
    same as c function atoi() which converts strings to integer equivalent
    ?

    Tks!
     
    lonelyplanet999, Oct 22, 2003
    #1
    1. Advertising

  2. Integer.parseInt(String str) and Integer.toString(int integer);


    "lonelyplanet999" <> wrote in message
    news:...
    > Hi,
    >
    > I would like to ask any java standard library function behaves the
    > same as c function atoi() which converts strings to integer equivalent
    > ?
    >
    > Tks!
     
    Frederic Pepin, Oct 22, 2003
    #2
    1. Advertising

  3. lonelyplanet999 wrote:

    > Hi,
    >
    > I would like to ask any java standard library function behaves the
    > same as c function atoi() which converts strings to integer equivalent
    > ?
    >
    > Tks!


    Short.parseInt(String)
    Inetger.parseInt(String)

    depending on what an 'int' was in that particular c compiler

    see also
    Byte.parseByte(String)
    Long.parseLong(String)
    Float.parseFloat(String)
    Double.parseDouble(String)

    and if you aren't thinking in base 10

    Integer.parseInt(String val, int radix)
     
    David Zimmerman, Oct 22, 2003
    #3
  4. lonelyplanet999

    Roedy Green Guest

    On 22 Oct 2003 09:56:07 -0700,
    (lonelyplanet999) wrote or quoted :

    >I would like to ask any java standard library function behaves the
    >same as c function atoi() which converts strings to integer equivalent


    http://mindprod.com/converter.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Oct 22, 2003
    #4
  5. David Zimmerman <> wrote in message news:<bKylb.3683$>...
    > lonelyplanet999 wrote:
    >
    > > Hi,
    > >
    > > I would like to ask any java standard library function behaves the
    > > same as c function atoi() which converts strings to integer equivalent
    > > ?
    > >
    > > Tks!

    >
    > Short.parseInt(String)
    > Inetger.parseInt(String)


    I tried applied parseInt to grab and decode numeric program arguments
    supplied from command line. Below is the implementation code.

    import java.lang.Integer;
    import java.lang.String;

    public class Argu {
    public static void main (String[] args) {
    for (int i=0; i<2; i++)
    System.out.println(parseInt(args));
    }
    }

    However, I got below compiler error as I compiled the code.

    Argu.java:7: cannot resolve symbol
    Symbol : method parseInt (java.lang.String)
    location : class Argu
    System.out.println(parseInt(args));
    ^
    1 error

    What's wrong with the code ? :)

    >
    > depending on what an 'int' was in that particular c compiler
    >
    > see also
    > Byte.parseByte(String)
    > Long.parseLong(String)
    > Float.parseFloat(String)
    > Double.parseDouble(String)
    >
    > and if you aren't thinking in base 10
    >
    > Integer.parseInt(String val, int radix)
     
    lonelyplanet999, Nov 2, 2003
    #5
  6. lonelyplanet999 wrote:
    >
    >
    > I tried applied parseInt to grab and decode numeric program arguments
    > supplied from command line. Below is the implementation code.
    >
    > import java.lang.Integer;
    > import java.lang.String;


    There is no need to import java.lang stuff. It is imported implicitly.

    >
    > public class Argu {
    > public static void main (String[] args) {
    > for (int i=0; i<2; i++)
    > System.out.println(parseInt(args));

    Should be:
    System.out.println(Integer.parseInt(args));
    > }
    > }
    >


    Also, you will need to catch the possible NumberFormatException that
    Integer.parseInt might throw, so the call to Integer.parseInt will need
    to be in a try block. Something like this:

    public static void main(String[] args) {
    for(int i = 0 ; i < args.length ; i++) {
    try {
    int x = Intger.parseInt(args);
    System.out.println("Number: " + x);
    }
    catch(NumberFormatException nfe) {
    System.out.println("Text: " + args);
    }
    }
    }

    Steve


    Steve
     
    Steve Horsley, Nov 2, 2003
    #6
  7. lonelyplanet999

    nos Guest

    you need Integer.parseInt() not just parseInt()

    "lonelyplanet999" <> wrote in message
    news:...
    > David Zimmerman <> wrote in message

    news:<bKylb.3683$>...
    > > lonelyplanet999 wrote:
    > >
    > > > Hi,
    > > >
    > > > I would like to ask any java standard library function behaves the
    > > > same as c function atoi() which converts strings to integer equivalent
    > > > ?
    > > >
    > > > Tks!

    > >
    > > Short.parseInt(String)
    > > Inetger.parseInt(String)

    >
    > I tried applied parseInt to grab and decode numeric program arguments
    > supplied from command line. Below is the implementation code.
    >
    > import java.lang.Integer;
    > import java.lang.String;
    >
    > public class Argu {
    > public static void main (String[] args) {
    > for (int i=0; i<2; i++)
    > System.out.println(parseInt(args));
    > }
    > }
    >
    > However, I got below compiler error as I compiled the code.
    >
    > Argu.java:7: cannot resolve symbol
    > Symbol : method parseInt (java.lang.String)
    > location : class Argu
    > System.out.println(parseInt(args));
    > ^
    > 1 error
    >
    > What's wrong with the code ? :)
    >
    > >
    > > depending on what an 'int' was in that particular c compiler
    > >
    > > see also
    > > Byte.parseByte(String)
    > > Long.parseLong(String)
    > > Float.parseFloat(String)
    > > Double.parseDouble(String)
    > >
    > > and if you aren't thinking in base 10
    > >
    > > Integer.parseInt(String val, int radix)
     
    nos, Nov 2, 2003
    #7
  8. lonelyplanet999

    Roedy Green Guest

    On 2 Nov 2003 07:11:42 -0800,
    (lonelyplanet999) wrote or quoted :

    >> > I would like to ask any java standard library function behaves the
    >> > same as c function atoi() which converts strings to integer equivalent


    for all your conversion needs, ask the Conversion amanuensis.

    http://mindprod.com/converter.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Nov 3, 2003
    #8
  9. lonelyplanet999

    ak Guest

    See http://gojava.imagero.com/


    "lonelyplanet999" <> schrieb im Newsbeitrag
    news:...
    > David Zimmerman <> wrote in message

    news:<bKylb.3683$>...
    > > lonelyplanet999 wrote:
    > >
    > > > Hi,
    > > >
    > > > I would like to ask any java standard library function behaves the
    > > > same as c function atoi() which converts strings to integer equivalent
    > > > ?
    > > >
    > > > Tks!

    > >
    > > Short.parseInt(String)
    > > Inetger.parseInt(String)

    >
    > I tried applied parseInt to grab and decode numeric program arguments
    > supplied from command line. Below is the implementation code.
    >
    > import java.lang.Integer;
    > import java.lang.String;
    >
    > public class Argu {
    > public static void main (String[] args) {
    > for (int i=0; i<2; i++)
    > System.out.println(parseInt(args));
    > }
    > }
    >
    > However, I got below compiler error as I compiled the code.
    >
    > Argu.java:7: cannot resolve symbol
    > Symbol : method parseInt (java.lang.String)
    > location : class Argu
    > System.out.println(parseInt(args));
    > ^
    > 1 error
    >
    > What's wrong with the code ? :)
    >
    > >
    > > depending on what an 'int' was in that particular c compiler
    > >
    > > see also
    > > Byte.parseByte(String)
    > > Long.parseLong(String)
    > > Float.parseFloat(String)
    > > Double.parseDouble(String)
    > >
    > > and if you aren't thinking in base 10
    > >
    > > Integer.parseInt(String val, int radix)
     
    ak, Nov 3, 2003
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Chirico
    Replies:
    2
    Views:
    3,871
    Grumble
    Nov 19, 2003
  2. mark
    Replies:
    2
    Views:
    18,342
    Victor Bazarov
    Jun 14, 2004
  3. Sonia

    atoi function

    Sonia, Feb 12, 2005, in forum: C++
    Replies:
    8
    Views:
    22,173
    Sonia
    Feb 13, 2005
  4. Allan Bruce

    Macro for atoi similar function

    Allan Bruce, Jul 4, 2003, in forum: C Programming
    Replies:
    6
    Views:
    1,145
    Allan Bruce
    Jul 5, 2003
  5. Bansidhar

    atoi function

    Bansidhar, Jan 30, 2004, in forum: C Programming
    Replies:
    5
    Views:
    7,213
    Peter Pichler
    Jan 30, 2004
Loading...

Share This Page