Ⅰ 怎么用java把输入的两串字符串中的数字提取出来,并且将两串数字相乘输出
解决方案:
使用正则表达式抽取数字子串;
使用Interger.parse将数字子串转为整数类型;
计算两个数字相乘即可;
Ⅱ JAVA如何从字符串中获得数字
首先求
该字符串
度
截取除
位
字符
OK
代码
假设String
str="100c";
int
i=str.length();//str.length
str.length()忘
自
试
int
tem=Integer.parseInt(str.subString(0,i-2));
tem
温度咯
Ⅲ java中怎么将字符串中的数字取出来
publicclass取数字
{
publicstaticvoidmain(String[]args)
{
System.out.println(" ==========将字符串中的数字取出来========== ");
init();
}//初始化!
privatestaticvoidinit()
{
//分割!
String[]s="今天是2017年09月01日".split("\D+");
//打印分割的!
for(inti=0;i<s.length;i++)
{
System.out.print(s[i]+"");
}
System.out.println();
}
}
Ⅳ Java如何从字符串中提取数字
使用正则表达式可以很方便地从文本中截取数字,下面是详细代码:
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
String phoneString = "哈哈,13888889999";
// 提取数字
// 1
Pattern pattern = Pattern.compile("[^0-9]");
Matcher matcher = pattern.matcher(phoneString);
String all = matcher.replaceAll("");
System.out.println("phone:" + all);
// 2
Pattern.compile("[^0-9]").matcher(phoneString).replaceAll("");
}
}
Ⅳ java如何截取字符串中的数字并计算
void calcNetIncome(String str){
int num = 0;
String temp = "";
for (int i = 0; i < str.length(); i++) {
if(str.charAt(i)=='-'||(str.charAt(i)>='0'&&str.charAt(i)<='9')){
while(i < str.length()){
temp+=str.charAt(i);
if(i+1 < str.length()&&(!(str.charAt(i+1)>='0'&&str.charAt(i+1)<='9'))){
break;
}
i++;
}
num+=Integer.parseInt(temp);
temp = "";
}
}
System.out.println(num);
}
Ⅵ java截取字符串中的数字,并且分组
用正则表达式按数字和中文的交界处切分字符串,就可以实现你的要求,完整的Java程序如下
public class F{
public static void main(String[] args){
String str="鱼豆腐20海带3掌中宝8鸡翅2可乐2";
String[] s=str.split("(?<=[0-9])(?=[u4e00-u9fa5])");
for(int i=0;i<s.length;i++){
System.out.println(s[i]);
}
}
}
Ⅶ java如何从任意字符串中截取数字
使用正则表达式可以很方便地从文本中截取数字,下面是详细代码:
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
String phoneString = "哈哈,13888889999";
// 提取数字
// 1
Pattern pattern = Pattern.compile("[^0-9]");
Matcher matcher = pattern.matcher(phoneString);
String all = matcher.replaceAll("");
System.out.println("phone:" + all);
// 2
Pattern.compile("[^0-9]").matcher(phoneString).replaceAll("");
}
}