编辑代码

class Main {
	public static void main(String[] args) {
		String allowPrivateChatAppVersion = "2.0.1";
		String userAppVersion = "1.0";
		System.out.println(versionComparison(allowPrivateChatAppVersion,userAppVersion));
	}
	public static int versionComparison(String aVersion,String bVersion){
		int intCheck = -1;
		if(aVersion.equals(bVersion)){
			intCheck=0;
			return intCheck;
		}
		String[] aVersions = aVersion.split("\\.");
		String[] bVersions = bVersion.split("\\.");
		int aInt=0;
		int bInt=0;
        int length = aVersions.length;
        if(bVersions.length>aVersions.length){
            length=bVersions.length;
        }
		for(int i=0; i<length;i++){
			if(aVersions.length <=i ){
				aInt=0;
			}else{
			    aInt = Integer.parseInt(aVersions[i]);
            }
            if(bVersions.length <=i ){
                bInt=0;
            }else{
			    bInt = Integer.parseInt(bVersions[i]);
            }
			if(aInt>bInt){
				intCheck=1;
                break;
			}else if(aInt==bInt){
				intCheck=0;
			}else if(aInt<bInt){
                intCheck=-1;
                break;
            }
		}
		return intCheck;
	}  
}