Question: int parseInt(String s) that extracts the integer (either positive or negative) whose digits are given as characters in the parameter string s. This method should
int parseInt(String s) that extracts the integer (either positive or negative) whose digits are given as characters in the parameter string s. This method should therefore work exactly like the standard library method Integer.parseInt. Of course, so that this problem wouldnt be trivial to begin with, you are not allowed to call that existing method (or the equivalent String.valueOf method) from your code, but must implement the internal logic all by yourself using only the basic String and integer operations of the Java language. For simplicity, you can assume that the parameter string s consists of one or more digit characters, possibly preceded by a minus sign, so that you dont need to handle underscore separators, legal in Java integer literals since Java 7. As always, you can also assume that input is always legal, so you dont need to detect non-digit characters or handle the integer overflow.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
