\"Translate each of the following English statements into logical tests that cou
ID: 3539391 • Letter: #
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.)
h. x and z are of opposite signs.
l. x is closer in value to y than z is."
I'm having a heck of a time trying to figure out h and l. The answers I came up with for h and l are both showing up as incorrect. Here's what I came up with:
h. (x > 0 && z < 0) || (x < 0 && z > 0)
i. (Math.abs(x) - Math.abs(y)) < (Math.abs(z) - Math.abs(y))
I'd greatly appreciate any other answers!
Explanation / Answer
h. x*z < 0
i. abs(x - y) < abs(x-z)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.