• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Meaning and Use of "parseint" method

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am a java beginner and I just saw this method
I also tried myself but I can't understand logic of it.
I don't know how the output is generated.
So can anyone explain me meaning of it and when it is used ??

Also tell me that when a simple parseint(String x) method is used.

Waiting for kind reply.
Thanks in advance.






OUTPUT :-
124
228
292
1092
172
364
444
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recommend taking a look at Oracle's webdocs on the Integer class.

When you use two parameters for the parseInt method, the first takes your string, tries to parse it, and the second is a radix - which is apparently the number of unique digits used to represent a number. So, "444" parsed using 5 unique digits is apparently 124. Unsure of the exact math but that is what the javadocs seem to say. Without the second parameter, the method simply takes your string and turns it into an int.


see http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html
 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Robert Lippens wrote:I recommend taking a look at Oracle's webdocs on the Integer class.

When you use two parameters for the parseInt method, the first takes your string, tries to parse it, and the second is a radix - which is apparently the number of unique digits used to represent a number. So, "444" parsed using 5 unique digits is apparently 124. Unsure of the exact math but that is what the javadocs seem to say. Without the second parameter, the method simply takes your string and turns it into an int.


see http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html



sorry but sir, I am still not clear about how its parsed and how 5 digits are passed and how output is generated.
Can you please explain simple parseint() method ??
 
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The second parameter is your Radix, i.e your base whether is needs to be parsed using base decimal , octal , hex or another you like.


do post back for any further queries.
 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Saif Asif wrote:The second parameter is your Radix, i.e your base whether is needs to be parsed using base decimal , octal , hex or another you like.


do post back for any further queries.



Thank you for replying sir,
I got satisfactory answer.
By the way, I also want to know why it is used ??
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dictionary Link.
 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Dictionary Link.



I wanted to know in terms of programming and also why is it used !!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because sometimes you have a number in the form of text (as a string), for example if a user entered it in a text box, and you need to convert it to an int, so that the computer can do calculations with it.
 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:Because sometimes you have a number in the form of text (as a string), for example if a user entered it in a text box, and you need to convert it to an int, so that the computer can do calculations with it.




Great sir,
I thought that it would be like this and I was true.
Thank you so much sir.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic