实例变量vs本地变量

时间:2019-05-11 16:42:19

标签: java

我是Java的新手,我需要一些明智的答案(JVM中正在发生什么)。 例如varible其工作正常。但是下面的代码越来越错误,为什么会这样,我需要在JVM中发生什么变化。

public class Binary {

    int remainder,count, maxCount;
    void binaryConvertor(int n){        
        while(n>0){
            remainder = n%2;
            if(remainder==1) {
                count++;
                if(maxCount<count)
                    maxCount=count;
            }
            else
                count=0;
            if(n==1)
                break;
            n/=2;
        }
    System.out.print(maxCount);
    }
}

此代码出错

public class Binary {


    void binaryConvertor(int n){
        int remainder,count, maxCount;
        while(n>0){
            remainder = n%2;
            if(remainder==1) {
                count++;
                if(maxCount<count)
                    maxCount=count;
            }
            else
                count=0;
            if(n==1)
                break;
            n/=2;
        }
    System.out.print(maxCount);
    }
}

0 个答案:

没有答案