January:05(Mon)
But if you still won't work in a team of two even considering the advantages/rewards I've indicated for that (say because you just can't do it for some reason), don't worry about other people receiving higher grades than you unfairly, just because they work in teams and you don't: I will determine grade cutoffs ("A-"/"B+", "B"/"B-", etc.) according to the base scores, not the scores with those extra rewards added. Thus, even if you work alone, you can still get scores that are considered perfect and thus get an "A" in this course.
argument2
wasn't null,
then
a second variable named argument1
shouldn't be
be null.
That is to say,
I wanted to express the following condition
in my Java code:
(argument2 ≠ null) → (argument1 ≠ null)
In case you're wondering,
the specific type of Java statement that I was writing here
was an assert statement;
but if you want you can consider the situation as though I was
writing an if statement as follows:
.
.
.
if ( _________ ) // "(argument2≠null) → (argument1≠null)"
{
.
.
.
Thus,
I wanted to complete the underline blank "________" there with
a Java expression
which would have
the value true
when argument2≠null is true
and argument1≠null is true,
the value false when
argument2≠null is true
and argument1≠null is false,
the value true when
argument2≠null is false
and argument1≠null is true,
and
the value true when
argument2≠null is false
and argument1≠null is false.
How can this problem be solved?
Give
a
Java expression that one could write in the
head of the
if statement here,
equivalent to the
logical expression "(argument2≠null) → (argument1≠null)". (You need to write just one
Java expression fitting in
the if statement
to solve this problem;
I'm not interested in code that is radically restructured or something.)
Explain why you think your answer is correct.
!(condition1 && condition2)
is logically equivalent to the
expression (!condition1 || !condition2),
and the
expression !(condition1 || condition2)
is logically equivalent to the
expression (!condition1 && !condition2).
(See De Morgan's Laws also in our textbook.)
For example,
the following three segments of code are all equivalent:
if ( !(num1 > num2 || num2 > num3) )
System.out.println("num2 is in the middle");
if ( !(num1 > num2) && !(num2 > num3) )
System.out.println("num2 is in the middle");
if ( num1 <= num2 && num2 <= num3 )
System.out.println("num2 is in the middle");
Then consider the following Java expressions:
!(x < 4) && !(y >= 7)
-
!(a == b) || !(g != 5)
-
!( x <= 8 && y > 3 )
-
!( i > 2 || j <= 9 )
!".
(You are allowed to use
the inequality operator "!=";
it is technically distinct from
Java's logical NOT operator, "!".)
Acknowledgement: This exercise was derived from "Java: How to Program" by Deitel & Deitel.