3 回答

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
正如文檔中明確指出Character.getNumericValue()的那樣,以數(shù)字形式返回字符的值。如果字符不是數(shù)字
,則返回-1。
如果要獲取裝箱Character對(duì)象的數(shù)字Unicode代碼點(diǎn),則需要先將其拆箱:
int value = (int)c.charValue();

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊
public class IntergerParser {
public static void main(String[] args){
String number = "+123123";
System.out.println(parseInt(number));
}
private static int parseInt(String number){
char[] numChar = number.toCharArray();
int intValue = 0;
int decimal = 1;
for(int index = numChar.length ; index > 0 ; index --){
if(index == 1 ){
if(numChar[index - 1] == '-'){
return intValue * -1;
} else if(numChar[index - 1] == '+'){
return intValue;
}
}
intValue = intValue + (((int)numChar[index-1] - 48) * (decimal));
System.out.println((int)numChar[index-1] - 48+ " " + (decimal));
decimal = decimal * 10;
}
return intValue;
}
添加回答
舉報(bào)