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 121 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
Excellent


tkempin

  • Member
  • Posts: 332
Reply 3 on: Yesterday
YES! Correct, THANKS for helping me on my review

 

Did you know?

The top 10 most important tips that will help you grow old gracefully include (1) quit smoking, (2) keep your weight down, (3) take supplements, (4) skip a meal each day or fast 1 day per week, (5) get a pet, (6) get medical help for chronic pain, (7) walk regularly, (8) reduce arguments, (9) put live plants in your living space, and (10) do some weight training.

Did you know?

It is believed that the Incas used anesthesia. Evidence supports the theory that shamans chewed cocoa leaves and drilled holes into the heads of patients (letting evil spirits escape), spitting into the wounds they made. The mixture of cocaine, saliva, and resin numbed the site enough to allow hours of drilling.

Did you know?

Calcitonin is a naturally occurring hormone. In women who are at least 5 years beyond menopause, it slows bone loss and increases spinal bone density.

Did you know?

Blood is approximately twice as thick as water because of the cells and other components found in it.

Did you know?

Allergies play a major part in the health of children. The most prevalent childhood allergies are milk, egg, soy, wheat, peanuts, tree nuts, and seafood.

For a complete list of videos, visit our video library