mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 17:56:02 +08:00
Update ParseInteger.java
Fixed error for empty string.
This commit is contained in:
@ -16,7 +16,7 @@ public class ParseInteger {
|
||||
* @throws NumberFormatException if the {@code string} does not contain a parsable integer.
|
||||
*/
|
||||
public static int parseInt(String s) {
|
||||
if (s == null) {
|
||||
if (s == null || s.length() == 0) {
|
||||
throw new NumberFormatException("null");
|
||||
}
|
||||
boolean isNegative = s.charAt(0) == '-';
|
||||
|
Reference in New Issue
Block a user