bug修改

This commit is contained in:
guoshengxiong 2024-06-18 18:16:57 +08:00
parent c46e7a0505
commit 46631c4913

View File

@ -6,6 +6,8 @@ import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Slf4j
public class NumberUtils {
@ -98,7 +100,7 @@ public class NumberUtils {
* @return
*/
public static Integer mod(Integer b1, Integer b2) {
if (b1 == null || b2 == null) {
if (b1 == null || b2 == null || b2.equals(0)) {
return null;
}
return b1 % b2;
@ -192,4 +194,21 @@ public class NumberUtils {
System.out.println(randomNum(6));
}
/**
* 获取字符串中的第一个数字
*
* @param str
* @return
*/
public static int getFirstNumberInStr(String str) {
String regex = "\\d+"; // 匹配一个或多个数字
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
return Integer.parseInt(matcher.group());
}
return -1;
}
}