0
Method repOk()
My question is is this work the same ? Code1: Public boolean repOk() { Return validateId(id) && validateName(name) && validateDob(dob); } Code2: Public boolean repOk() { If (!(validateId(id)) || !(validateName(name)) || !(validateDob(dob))) { return false; } else { return true; } *)Note that method validate check is id, name or dob valid. I think it work the same but i'm not sure
4 Respostas
+ 1
First code returns true if everything is valid.
Second code returns false if one thing isn't valid.
Since you have only 3 booleans in there and you are not sure, you can check if it outputs the same thing on paper.
You can also check de Morgan's laws.
+ 1
Adam Priesnitz so first code will return false if one thing is not valid, right? So code 1 and code 2 are the same right ?
+ 1
Yes, they both return the same output.
In first code you check if everything is true and in the second code if something is false.
0
Adam Priesnitz many thanks