例如:ss16d1wd16sdsw2134,提取出来的整数为16
最后输出的16进制为:10
public class Test06 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "ss16d1wd16sdsw2134";
String b ="";
for (int i = 0; i < str.length(); i++) {
if(str.charAt(i)>=48 && str.charAt(i)<=57){
b+=str.charAt(i);
if(!(str.charAt(i+1)>=48 && str.charAt(i+1)<=57)) {
break;
}
}
}
System.out.println("从字符串中提取出来的整数为:"+b);
Integer numm = Integer.parseInt(b);
System.out.println("提取出来的整数的二进制为:"+Integer.toBinaryString(numm));
System.out.println("提取出来的整数的八进制为:"+Integer.toOctalString(numm));
System.out.println("提取出来的整数的十六进制为:"+Integer.toHexString(numm));
}
}
从字符串中提取出来的整数为:16
提取出来的整数的二进制为:10000
提取出来的整数的八进制为:20
提取出来的整数的十六进制为:10