bug修改
This commit is contained in:
parent
c46e7a0505
commit
46631c4913
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user