導航:首頁 > 編程語言 > 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字元串提取數字相關的資料

熱點內容
資料庫查詢系統源碼 瀏覽:611
php5314 瀏覽:350
完美國際安裝到哪個文件夾 瀏覽:663
什麼app可以掃一掃做題 瀏覽:534
程序員編碼論壇 瀏覽:918
淘點是什麼app 瀏覽:654
中國高等植物pdf 瀏覽:447
51單片機時間 瀏覽:176
後台如何獲取伺服器ip 瀏覽:260
單片機流水燈程序c語言 瀏覽:227
程序員第二職業掙錢 瀏覽:234
運行里怎麼輸入伺服器路徑 瀏覽:833
pythonstepwise 瀏覽:502
劉一男詞彙速記指南pdf 瀏覽:56
php認證級別 瀏覽:361
方舟編譯啥時候推送 瀏覽:1003
php手機驗證碼生成 瀏覽:669
哲學思維pdf 瀏覽:9
凌達壓縮機有限公司招聘 瀏覽:527
weblogic命令部署 瀏覽:30