public class compareVersion {
public static void main(String[] args){
String v1="1.0.358";
String v2="1.0.358_20180820090553";
String[] v1s=v1.split("[._]");
String[] v2s=v2.split("[._]");
int i=0,j=0;
while (i<v1s.length&&j<v2s.length){
if(v1s[i].compareTo(v2s[j])>0){
System.out.println("V1大");
break;
}
else if(v1s[i].compareTo(v2s[j])<0){
System.out.println("V2大");
break;
}
i++;j++;
}
if(i==v1s.length&&v2s.length==j){
System.out.println("V1=V2");
}else if(i<v1s.length){
System.out.println("V1大");
}else if(j<v2s.length){
System.out.println("V2大");
}
}
}
网友评论