String to Integer

How to convert a string variable to integer variable without using Integer.parseInt() fuction
Who is Participating?
Loop thru the characters from last to first
for each character convert it to a number,  int n = (int) c - '0'
and mutlipy it by a multiplier which is initially 1, and add the result to your result value
for every loop, multipy the multiplier by 10

let me know if u get stuick :)
Mayank SAssociate Director - Product EngineeringCommented:
Use valueOf () ;-)

Oops, this has been asked before:
Mayank SAssociate Director - Product EngineeringCommented:
That is somebody's homework done.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

> Aks him how many of his  comments I deleted

Not that many that I can recall :) But some yes.
Mayank SAssociate Director - Product EngineeringCommented:
He he he he.... there is a reason why objects did not post full-code. You think him or I couldn't have written it ;-) ?
Hi aeltech,

See link posted by mayankeagle:
for each digit : value=value*10+(digit-'0');

And if you have signed values, check if first character is '+' or '-' or digit, if '-' then return -value
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.