|
-
May 8th, 2006, 05:14 AM
#1
Thread Starter
Frenzied Member
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?
-
May 8th, 2006, 01:55 PM
#2
Addicted Member
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())
-
May 8th, 2006, 05:35 PM
#3
Re: how can i cut this code size down
 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."))
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|