Translate each of the following English statements into logical tests that could
ID: 3631163 • Letter: T
Question
Translate each of the following English statements into logical tests that could be used in an if/else statement. Write the appropriate logical test for each statement below. Assume that three int variables, x, y, and z, have already been declared.(Note: This problem is currently not very well implemented in Practice-It. Right now our system is just checking whether your answer exactly matches our expected answer, but some other correct answers might be marked as incorrect even though they would work. We plan to improve the system in the future. Sorry for the inconvenience.)
a. z is odd.
b. z is not greater than y's square root.
c. y is positive.
d. Either x or y is even, and the other is odd.
e. y is a multiple of z.
f. z is not zero.
g. y is greater in magnitude than z.
h. x and z are of opposite signs.
i. y is a nonnegative one-digit number.
j. z is nonnegative.
k. x is even
l. x is closer in value to y than z is.
I don't understand why I'm getting it wrong...
Explanation / Answer
please rate - thanks
may be beacuse of this disclaimer
Note: This problem is currently not very well implemented in Practice-It. Right now our system is just checking whether your answer exactly matches our expected answer, but some other correct answers might be marked as incorrect even though they would work. We plan to improve the system in the future. Sorry for the inconvenience.)
a. z is odd. z%2==1
b. z is not greater than y's square root. z<=sqrt(y)
c. y is positive. y>0
d. Either x or y is even, and the other is odd. (x%2==0&&y%2==1)||(x%2==1&&y%2==0)
e. y is a multiple of z. y%z==0
f. z is not zero. z!=0
g. y is greater in magnitude than z. abs(y)>abs(z)
h. x and z are of opposite signs. (x>0&&z<0)||(x<0&&z>0)
i. y is a nonnegative one-digit number. y>=0&&y<10
j. z is nonnegative. z>=0
k. x is even x%2==0
l. x is closer in value to y than z is. abs(x-y)<abs(z-y)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.