public class Test {
public static void main(String[] args) {
String oldVersion = "0.3.0";// 假设原先的版本号为0.3.0
String newVersion = "0.2.8";// 要校验的版本号为0.2.8
boolean b = checkVersion(oldVersion, newVersion);
System.out.println("版本号是否通过:" + b);
}
public static boolean checkVersion(String oldVersion, String newVersion) {
String regex = "(\\d\\.){2}\\d";// 正则表达式
// 先判断版本号格式
boolean flag = newVersion.matches(regex);
if (flag) {
int i = (oldVersion);
if (i < 0)
flag = false;
}
return flag;
}
}