943,923 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 11860
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Feb 27th, 2008
0

Re: String to int

Click to Expand / Collapse  Quote originally posted by Ezzaral ...
97 is the byte value of 'a'. Your read() call just got a single byte and converted it to int.

In any case, it's irrelevant. Without a stated encoding expectation, "asu" cannot be converted to int. Integer.parseInt() will convert a valid integer string to an int value. If you want to convert some other string to an int, there are many different ways to do so, but they are specific encoding methods - not just a general api call or statement.
even if you write Integer.parsrInt("asu"); you will get Number format exception but if you write Integer.parseInt("197") it will give the number 197.
Reputation Points: 9
Solved Threads: 1
Light Poster
Parsu7 is offline Offline
29 posts
since Feb 2008
Feb 27th, 2008
0

Re: String to int

Click to Expand / Collapse  Quote originally posted by Parsu7 ...
even if you write Integer.parsrInt("asu"); you will get Number format exception but if you write Integer.parseInt("197") it will give the number 197.
Of course, which is already mentioned. You are missing the entire point.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Feb 27th, 2008
0

Re: String to int

Click to Expand / Collapse  Quote originally posted by Ezzaral ...
Of course, which is already mentioned. You are missing the entire point.
I would be really gratefull to you if you could tell me the point which i am missing.
Reputation Points: 9
Solved Threads: 1
Light Poster
Parsu7 is offline Offline
29 posts
since Feb 2008
Feb 27th, 2008
0

Re: String to int

Integer.parseInt() was already explained. The real point is that there is no generic method to make "asu" an int. It is totally dependent upon how you need to encode the string and that is totally dependent on what you intend to use it for.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Feb 27th, 2008
0

Re: String to int

Click to Expand / Collapse  Quote originally posted by Ezzaral ...
Integer.parseInt() was already explained. The real point is that there is no generic method to make "asu" an int. It is totally dependent upon how you need to encode the string and that is totally dependent on what you intend to use it for.
Thanks, but can we write this to convert a string such as "asu" to integer

int x = br.read();
int y=br.read();
int z=br.read();

System.out.println(x+y+z);

Please do reply me.
Reputation Points: 9
Solved Threads: 1
Light Poster
Parsu7 is offline Offline
29 posts
since Feb 2008
Feb 27th, 2008
0

Re: String to int

You could, but what would the point be?
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Feb 27th, 2008
0

Re: String to int

You can write whatever you want if this is the way you want to convert "asu" to a String. As it was said in the first reply what do you want to convert "asu" to?
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,259 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: NoClassDefFounderError
Next Thread in Java Forum Timeline: Java Paint Program Question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC