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 118 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
Wow, this really help


juliaf

  • Member
  • Posts: 344
Reply 3 on: Yesterday
:D TYSM

 

Did you know?

To combat osteoporosis, changes in lifestyle and diet are recommended. At-risk patients should include 1,200 to 1,500 mg of calcium daily either via dietary means or with supplements.

Did you know?

Russia has the highest death rate from cardiovascular disease followed by the Ukraine, Romania, Hungary, and Poland.

Did you know?

In women, pharmacodynamic differences include increased sensitivity to (and increased effectiveness of) beta-blockers, opioids, selective serotonin reuptake inhibitors, and typical antipsychotics.

Did you know?

Over time, chronic hepatitis B virus and hepatitis C virus infections can progress to advanced liver disease, liver failure, and hepatocellular carcinoma. Unlike other forms, more than 80% of hepatitis C infections become chronic and lead to liver disease. When combined with hepatitis B, hepatitis C now accounts for 75% percent of all cases of liver disease around the world. Liver failure caused by hepatitis C is now leading cause of liver transplants in the United States.

Did you know?

Automated pill dispensing systems have alarms to alert patients when the correct dosing time has arrived. Most systems work with many varieties of medications, so patients who are taking a variety of drugs can still be in control of their dose regimen.

For a complete list of videos, visit our video library