我有一个由数字序列组成的字符串 (例如 "1234"
)。如何在不使用 Java 库函数(比如 Integer.parseInt
)的情况下将这个 String
转换为 int
呢?
public class StringToInteger {
public static void main(String [] args){
int i = myStringToInteger("123");
System.out.println("String decoded to number " + i);
}
public int myStringToInteger(String str){
/* ... */
}
}
Integer.parseInt()
函数,请复制粘贴其代码。为什么要提出这样一个荒谬的要求? - JB Nizet