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 120 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
Great answer, keep it coming :)


sultana.d

  • Member
  • Posts: 320
Reply 3 on: Yesterday
Gracias!

 

Did you know?

The strongest synthetic topical retinoid drug available, tazarotene, is used to treat sun-damaged skin, acne, and psoriasis.

Did you know?

Acetaminophen (Tylenol) in overdose can seriously damage the liver. It should never be taken by people who use alcohol heavily; it can result in severe liver damage and even a condition requiring a liver transplant.

Did you know?

Everyone has one nostril that is larger than the other.

Did you know?

Medications that are definitely not safe to take when breastfeeding include radioactive drugs, antimetabolites, some cancer (chemotherapy) agents, bromocriptine, ergotamine, methotrexate, and cyclosporine.

Did you know?

Many medications that are used to treat infertility are injected subcutaneously. This is easy to do using the anterior abdomen as the site of injection but avoiding the area directly around the belly button.

For a complete list of videos, visit our video library