how can i cut this code size down
Code:
if (result == "Congratulations! Your guess was correct.") {
String end = "Game over. You guessed correctly.";
out.writeUTF(end);
out.flush();
client.close();
server.close();
break;
}
else if (mnumb.getFinished()) {
String end = "Game over. You exceeded maximum number of guesses.";
out.writeUTF(end);
out.flush();
client.close();
server.close();
break;
}
else {
out.writeUTF(result);
out.flush();
}
the 2 first if statements perfrom the same action, except the string message is different.. im sure i can cut duplicating code out?
Re: how can i cut this code size down
you can use the or opperator || to conect the two if statements
Code:
if (result == "Congratulations! Your guess was correct." || mnumb.getFinished())
Re: how can i cut this code size down
Quote:
Originally Posted by TBeck
you can use the or opperator || to conect the two if statements
Code:
if (result == "Congratulations! Your guess was correct." || mnumb.getFinished())
That's not right, the end String is different in each statement.
and you cannot compare strings like that, it'll never return true, you should use
Code:
if(result.equals("Congratulations! Your guess was correct."))