导航:首页 > 编程语言 > java字符串提取数字

java字符串提取数字

发布时间:2022-06-24 04:14:57

Ⅰ 怎么用java把输入的两串字符串中的数字提取出来,并且将两串数字相乘输出

解决方案:

  1. 使用正则表达式抽取数字子串;

  2. 使用Interger.parse将数字子串转为整数类型;

  3. 计算两个数字相乘即可;

Ⅱ 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("");
}
}

阅读全文

与java字符串提取数字相关的资料

热点内容
python集合中插入元素 浏览:170
oms会检测编译程序吗 浏览:793
开考前命令话 浏览:354
安卓键盘怎么设置虚拟按键 浏览:93
苹果笔记本电脑怎么登录云服务器 浏览:932
为什么安卓手机比苹果耐寒 浏览:718
滴滴出行app什么时候恢复正常下载 浏览:560
python中turtle绘制图形并保存 浏览:565
php获取上个月时间戳 浏览:574
怎么设置oppo手机app密码 浏览:360
jra格式下载哪个文件夹 浏览:658
苹果手机怎么删除手机上的app 浏览:343
单片机热敏电阻温度控制 浏览:82
方舟私人服务器的服主怎么刷物资 浏览:454
重装系统提示加密锁 浏览:625
为什么下载的音乐要加密 浏览:964
因为没有打开的文档所以这一命令无效 浏览:720
电脑文件夹数据损坏 浏览:716
java打赏源码搭建 浏览:365
pdf32 浏览:256