Results 1 to 9 of 9
  1. #1
    mcfer is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default Need some help understanding Parsing

    i have this particular code

    public class Numbers{
    public static void main(String args[]){

    Integer x =Integer.valueOf(9);
    Double c = Double.valueOf(5);
    Float a = Float.valueOf("80");

    System.out.println(x);
    System.out.println(c);
    System.out.println(a);
    System.out.println(b);
    }
    }

    after execution it gives the outputs

    9
    5.0
    80.0
    1092

    Could anyone explain how "1092" comes up after execution of "Integer b = Integer.valueOf( "444",16);" how does it parse the argument "444" ?

    Thank you.

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    6

    Default

    You specified the radix as 16. Since hexadecimal 444 is equal to decimal 1092, that's what it displays.

  3. #3
    mcfer is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default

    Thank you. that is understood..but radix could be any number.. let say radix=20..will it affect the output ?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,290
    Blog Entries
    7
    Rep Power
    24

    Default

    Quote Originally Posted by mcfer View Post
    Thank you. that is understood..but radix could be any number.. let say radix=20..will it affect the output ?
    Yup, if the radix is 20 the number 444 represents 4*(20*20)+4*(20)+4 == 1684

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  5. #5
    mcfer is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default

    Thank you...

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    18,973
    Rep Power
    28

    Default

    will it affect the output
    Write a short test program and try different values and see.

  7. #7
    Preethi5 is offline Member
    Join Date
    Sep 2015
    Posts
    1
    Rep Power
    0

    Default Re: Need some help understanding Parsing

    When I give Radix=2 I'm getting an error. can you plz explain on this?

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,988
    Rep Power
    21

    Default Re: Need some help understanding Parsing

    When the radix is 2, the only valid digits are 0 and 1.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,988
    Rep Power
    21

    Default Re: Need some help understanding Parsing

    Looks like you haven't actually understood the meaning of Radix

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Need some understanding and help!
    By Kevinius in forum New To Java
    Replies: 8
    Last Post: 05-14-2011, 05:50 AM
  2. Help with understanding Threads
    By samp in forum Java Applets
    Replies: 2
    Last Post: 03-09-2011, 07:46 PM
  3. Understanding this recursion
    By Yakg in forum New To Java
    Replies: 6
    Last Post: 01-05-2011, 10:39 PM
  4. need help in understanding collection
    By ShinTec in forum Advanced Java
    Replies: 2
    Last Post: 04-24-2010, 02:49 AM
  5. Help on understanding a program
    By newbie225 in forum New To Java
    Replies: 1
    Last Post: 11-10-2009, 01:53 AM

Posting Permissions

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