Consider the following code segment where m is a variable of

Consider the following code segment, where m is a variable of the type int: if (m > 0) {if ((1000/m) % 2 == 0) System.out.println(\"even\"); else System.out.println(\"odd\");} else System.out.println(\"not positive\"); Which of the following code segments are equivalent to the one above (that is, produce the same output as the one above regardless of the value of m)? if (m o 0) System.out .print In (\"not positive\'1); else if ((1000/m) % 2 - 0) System.out.println(\"even\"); else System.out.printIn(\"odd\"); if (m > 0 && (1000/m) % 2 == 0) System.out.println(\"even\"); else if (m

Solution

Answer is I and II.

III cannot be the answer because if m = 0 then above code will give the zero divison exception which cannot happen in the original code and code fragments I and II.

hence C is the answer.

 Consider the following code segment, where m is a variable of the type int: if (m > 0) {if ((1000/m) % 2 == 0) System.out.println(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site