Results 1 to 6 of 6
  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
    4

    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
    13,309
    Blog Entries
    7
    Rep Power
    20

    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
    cenosillicaphobia: the fear for an empty beer glass

  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 offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

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

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, 06:46 PM
  3. Understanding this recursion
    By Yakg in forum New To Java
    Replies: 6
    Last Post: 01-05-2011, 09: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, 12: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
  •