Getting constant false value from method

前端 未结 3 537
迷失自我
迷失自我 2021-01-21 17:42

I have 3 questions

 private static int NUMBER_OF_QUESTIONS = 3;
static boolean[] answer = new boolean[NUMBER_OF_QUESTIONS];
static boolean[] checked = new boolea         


        
3条回答
  •  死守一世寂寞
    2021-01-21 18:15

    I have implemented a quick class to validate your logic and found no problems in your implementation.

    public class MainActivity extends AppCompatActivity {
    
        private static int NUMBER_OF_QUESTIONS = 3;
        static boolean[] isAnswered = new boolean[NUMBER_OF_QUESTIONS];
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            setBooleanValues();
            allAnswersChecked();
        }
    
        private void setBooleanValues() {
            isAnswered[0]=true;
            isAnswered[1]=false;
            isAnswered[2]=true;
        }
    
        private void allAnswersChecked() {
            for (boolean radioAnswer : isAnswered) {
                if (!radioAnswer) {
                    //return false;
                    Log.d("allAnswersChecked","false");
                }
                else {
                    Log.d("allAnswersChecked","true");
                }
            }
            //return true;
        }
    
    }
    

    See the log output :

    05-12 16:43:10.299 8448-8448/com.example.myapplicationtest D/allAnswersChecked: true
    05-12 16:43:10.299 8448-8448/com.example.myapplicationtest D/allAnswersChecked: false
    05-12 16:43:10.299 8448-8448/com.example.myapplicationtest D/allAnswersChecked: true
    

    So I recomment to print values and check if it is being correct set into your isAnswered array before calling allAnswersChecked().

提交回复
热议问题