if else statements
if-statement, java
Solution
Everything is fine except the last else if. Where you accidentely did an assignment rather than comparison.
else if(score1=score2)
The above else-if statement should be: -
else if(score1 == score2)
P.S: - In fact, you can remove the last `else if` with just simple `else` That will be equivalent to this else if. Since you have already considered your other possibility in your first two condition.
So, this will also do it: -
else {
System.out.println("tie");
tieCount++;
}
Problem
I'm having a problem with this question can anyone help? an explanation would be nice rather than the answer the answer it self. Write a statement that compares the values of score1 and score2 and takes the following actions. When score1 exceeds score2 , the message "player1 wins" is printed to standard out. When score2 exceeds score1 , the message "player2 wins" is printed to standard out. In each case, the variables player1Wins, , player1Losses , player2Wins, and player2Losses, , are incremented when appropriate. Finally, in the event of a tie, the message "tie" is printed and the variable tieCount is incremented. ``` if(score1>score2) { System.out.println("player1 wins"); player1Wins++;player2Losses++; } else if(score2>score1) { System.out.println("player2 wins"); player2Wins++;player1Losses++; } else if(score1=score2) { System.out.println("tie"); tieCount++; } ```