I have written a simple for loop with an if-else block inside it for an android app. The code looks like this:
for (int i = 0; i < ques.length; i++) {
int attempt=0;
int j=i+1;
ans1 = t.getText().toString();
if (ans1.equals(ans[i])) {
qView.setText("");
t.setText("");
aview.setText("");
if(j!=ques.length) {
aview.append("Attempts: 0");
qView.append(ques[j]);
}
else
qView.append("Congrats!You have completed the quiz");
}
else {
attempt++;
aview.setText("wrong");
//aview.append("Attempts: " + attempt);
}
When I run the app and enter the correct answer to match the if condition, the commands t.setText("") and qView.setText("") get executed, however for aview, the command under else (aview.setText("wrong")) gets executed. Why is this happening? How is it possible that both if and else blocks are being executed for the same input?
Aucun commentaire:
Enregistrer un commentaire