怎么变换方法中变量的值

图片说明
如图,我想每次执行这个方法的时候要count的值都不和上次执行的重复,求指教

把count设置为全局变量,或者全局静态变量,并且要注意其线程安全性;
比如:
private final static AtomicInteger cnt = new AtomicInteger(0);

public void test(){
//这里就能保证你的每次调用都是在0和1之前变换。并且线程安全
int count = cnt.getAndAdd() % 2;
//你的逻辑
}

希望能帮到你....

设置count为全局变量,既然要count在0和1切换的话,建议用boolean型
执行test 函数 中加入count=count?false:true;就可以了