how to convert string to int without using any standard function in java. write an algorithm that implements parseInt?
Joined: Jan 17, 2006
Depends on what you mean by standard functions. Off the top of my head you could take a String, examine it to be sure that is contains all digits (simple if you use a regular expression, but is that allowed?), reverse the String, examine each digit, convert it to an int (or Integer) using some sort of mapping, multipliy it by the appropriate power of 10, and add the result to the total. Sounds pretty easy, but I'd rather use Integer.parseInt().
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
author and iconoclast