导航:首页 > 编程语言 > 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字符串提取数字相关的资料

热点内容
数据库查询系统源码 浏览:614
php5314 浏览:354
完美国际安装到哪个文件夹 浏览:666
什么app可以扫一扫做题 浏览:537
程序员编码论坛 浏览:923
淘点是什么app 浏览:658
中国高等植物pdf 浏览:453
51单片机时间 浏览:181
后台如何获取服务器ip 浏览:265
单片机流水灯程序c语言 浏览:232
程序员第二职业挣钱 浏览:237
运行里怎么输入服务器路径 浏览:840
pythonstepwise 浏览:509
刘一男词汇速记指南pdf 浏览:62
php认证级别 浏览:366
方舟编译啥时候推送 浏览:1010
php手机验证码生成 浏览:675
哲学思维pdf 浏览:14
凌达压缩机有限公司招聘 浏览:534
weblogic命令部署 浏览:36