• Post Reply Bookmark Topic Watch Topic
  • New Topic

Meaning and Use of "parseint" method  RSS feed

 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • 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
 
Robert Lippens
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
  • 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 ??
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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 ??
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dictionary Link.
 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Dictionary Link.


I wanted to know in terms of programming and also why is it used !!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!