|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (7 bit)
|
Java help
Hey, I'm using Dr. Java in my intro to programming class at IU. We need to write this class (in the attached file) not using 'if' statements. I think i need to use the boolean operators ! && || to accomplish this. From what i've read, however, this will only output results of True or False. I need to be able to check the value of my String message (current code also attached) to see if its null, then output 1 of 2 statements based on its being true or false. If anyone can help me please, i would be very grateful.
|
|
|
|
|
|
#2 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
Is it OK to use the ?: operator?
Code:
return message == null ?
"there's no message here" : "there's one message waiting for pickup";
|
|
|
|
|
|
#3 |
|
Come in Ray...
Join Date: Sep 2004
Posts: 1,668
|
Don't mess with nulls if you don't have to. Make your default message an empty string ("") and use a switch statement to do the comparisons.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|