Ask coding questions

← Back to all posts
Java programming question
mwabonje1

The following code should count the number of correct responses and give me the count at the end. when there is invalid input it should loop the question until valid input is keyed whether right or wrong. However, it is not able to recognize valid wrong answers from invalid answers

Voters
AtienzaGuidel
mwabonje1
Comments
hotnewtop
a5rocks

You forgot to put braces around the stuff in the else statement on line 14.

Also, you forgot to put a break in the else if.

ALSO, you did answer2 != ("B")||answer2 !=("C")||answer2 !=("D")||answer2 !=("E"), which isn't correct as (if you apply basic boolean algebra rules) you are just checking if the answer isn't simultaneously B, C, D, and E. Basically, answer2 != ("B")||answer2 !=("C") is always going to be true, true||whatever is always going to be true.

mwabonje1

import javax.swing.JOptionPane;
public class Test {

}

i have done the above code but it is not working as per my expectation. I wanted it to record right answers and show me the number of questions i got. Also it should tell me to input a valid answer if one has entered a choice that isn't available.