String to Integer

How to convert a string variable to integer variable without using Integer.parseInt() fuction
aeltechAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
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 :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
Use valueOf () ;-)

Oops, this has been asked before:

http://forum.java.sun.com/thread.jspa?threadID=675339&messageID=3943530
0
Mayank SAssociate Director - Product EngineeringCommented:
That is somebody's homework done.
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Mick BarryJava DeveloperCommented:
> Aks him how many of his  comments I deleted

Not that many that I can recall :) But some yes.
0
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 ;-) ?
0
WebstormCommented:
Hi aeltech,

See link posted by mayankeagle:
value=0;
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.