This topic contains a solution. Click here to go to the answer

Author Question: Analyze the following code fragments that assign a boolean value to the variable even.Code 1: if ... (Read 133 times)

hubes95

  • Hero Member
  • *****
  • Posts: 561

Question 1

What is y after the following statement is executed?

x = 0;
y = (x > 0) ? 10 : -10;

◦ -10
◦ 0
◦ 20
◦ 10
◦ Illegal expression

Question 2

Analyze the following code fragments that assign a boolean value to the variable even.

Code 1:
if (number % 2 == 0)
even = true;
else
even = false;

Code 2:
even = (number % 2 == 0) ? true: false;

Code 3:
even = number % 2 == 0;

◦ All three are correct, but Code 2 is preferred.
◦ All three are correct, but Code 1 is preferred.
◦ Code 3 has a compile error, because you attempt to assign number to even.
◦ Code 2 has a compile error, because you cannot have true and false literals in the conditional expression.
◦ All three are correct, but Code 3 is preferred.


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by hubes95 on May 6, 2020

flannelavenger

  • Sr. Member
  • ****
  • Posts: 322
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 25% of students answer this correctly




hubes95

  • Member
  • Posts: 561
Reply 2 on: May 6, 2020
Gracias!


momolu

  • Member
  • Posts: 320
Reply 3 on: Yesterday
Great answer, keep it coming :)

 

Did you know?

Hippocrates noted that blood separates into four differently colored liquids when removed from the body and examined: a pure red liquid mixed with white liquid material with a yellow-colored froth at the top and a black substance that settles underneath; he named these the four humors (for blood, phlegm, yellow bile, and black bile).

Did you know?

People who have myopia, or nearsightedness, are not able to see objects at a distance but only up close. It occurs when the cornea is either curved too steeply, the eye is too long, or both. This condition is progressive and worsens with time. More than 100 million people in the United States are nearsighted, but only 20% of those are born with the condition. Diet, eye exercise, drug therapy, and corrective lenses can all help manage nearsightedness.

Did you know?

Walt Disney helped combat malaria by making an animated film in 1943 called The Winged Scourge. This short film starred the seven dwarfs and taught children that mosquitos transmit malaria, which is a very bad disease. It advocated the killing of mosquitos to stop the disease.

Did you know?

More than 4.4billion prescriptions were dispensed within the United States in 2016.

Did you know?

The first oncogene was discovered in 1970 and was termed SRC (pronounced "SARK").

For a complete list of videos, visit our video library