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

熱點內容
代碼加密常用方法 瀏覽:952
安卓手機如何解除已禁用 瀏覽:396
演算法的隨機性 瀏覽:485
高中解壓體育游戲 瀏覽:532
androidstudior丟失 瀏覽:345
命令行筆記 瀏覽:737
360目標文件夾訪問拒絕 瀏覽:518
3b編程加工指令 瀏覽:789
c8051f系列單片機選型手冊 瀏覽:772
南昌php程序員 瀏覽:511
bcs命令 瀏覽:446
如何在伺服器指向域名 瀏覽:417
車床編程可以做刀嗎 瀏覽:519
ln命令源碼 瀏覽:791
用粘液做解壓手套 瀏覽:331
icloud收信伺服器地址 瀏覽:500
編程思考者 瀏覽:453
壓縮機型號用什麼氟利昂 瀏覽:553
農機空氣壓縮機 瀏覽:666
程序員下載歌曲 瀏覽:897