We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

String to Integer

aeltech
aeltech asked
on
Medium Priority
365 Views
Last Modified: 2010-03-31
How to convert a string variable to integer variable without using Integer.parseInt() fuction
Comment
Watch Question

Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
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 :)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mayank SPrincipal Technologist
CERTIFIED EXPERT
Commented:
Use valueOf () ;-)

Oops, this has been asked before:

http://forum.java.sun.com/thread.jspa?threadID=675339&messageID=3943530
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
That is somebody's homework done.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> Aks him how many of his  comments I deleted

Not that many that I can recall :) But some yes.
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
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 ;-) ?
Top Expert 2004

Commented:
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.