0
$\begingroup$

I have this question, which I don't understand.

Let $x$ and $m$ be integer variables. The variable $m$ always holds a positive number after executing the following code: if (x > 10) {m = x - 7;} else {m = 5;}

Since it's assessed work, I do not want help. However, I've got a similar question in my notes. I was hoping if someone could explain to me how the similar question answer has been founded, I'll be able to apply the technique into my other question.

http://vvcap.net/db/MQBULlSPcXfS4WjsIE3p.htp

Here is the note for the similar question. It has the answer but I don't really understand how they got it.

$\endgroup$
0
$\begingroup$

In the example 2: The cases are based on the if statement, and it seems they are using "case 1" to mean when the Boolean after "if" is true, and "case 2" when that Boolean is false.

So in the particular example 2, for case 1 the "assumption" is that $x<0$, and the output is then just given to be $y=10$ (which is greater than or equal to zero). And for case 2 the assumption is that it is false that $x<0$, so that in fact $x \ge 0$, and the output is then given as $y=x$, which is again greater than or equal to zero since in this "case 2" the value of $x$ is nonnegative by the case assumption.

This idea should work on your assessed problem.

$\endgroup$
  • $\begingroup$ Ah ok, thanks a lot ! think i got it :D $\endgroup$ – user113523 Dec 6 '13 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.