package com.ssdou;
import java.util.Scanner;
public class Translate {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
String a = input.nextLine();
String b = a.toLowerCase();
StringBuffer c =new StringBuffer("");
for (int i=0;i<a.length();i++){
if ('o'>b.charAt(i)&&b.charAt(i)>'g'){
c = c.append(b.charAt(i));
}
}
String d = ""+c;
System.out .println("十进制数为:"+ Integer.parseInt(d, 10));
}
}这里System.out .println("十进制数为:"+ Integer.parseInt(d, 10));
会产生Exception in thread "main" java.lang.NumberFormatException: For input string: ""异常
怎么解决
1 回答
f_life
TA贡献1条经验 获得超0个赞
首先你输入的字符必须在g—o之间的,再次Integer.parseInt(String,int),int为10的话,这个方法String 必须是数字类型的字符串,也就是说能被解析为数字的字符串;当然如果int为16,27的话,String必须为其进制的相应的字母或数字
Examples:
parseInt("0", 10) returns 0
parseInt("473", 10) returns 473
parseInt("+42", 10) returns 42
parseInt("-0", 10) returns 0
parseInt("-FF", 16) returns -255
parseInt("1100110", 2) returns 102
parseInt("2147483647", 10) returns 2147483647
parseInt("-2147483648", 10) returns -2147483648
parseInt("2147483648", 10) throws a NumberFormatException
parseInt("99", 8) throws a NumberFormatException
parseInt("Kona", 10) throws a NumberFormatException
parseInt("Kona", 27) returns 411787
添加回答
举报
0/150
提交
取消