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 122 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


Animal_Goddess

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

 

Did you know?

The top five reasons that children stay home from school are as follows: colds, stomach flu (gastroenteritis), ear infection (otitis media), pink eye (conjunctivitis), and sore throat.

Did you know?

It is important to read food labels and choose foods with low cholesterol and saturated trans fat. You should limit saturated fat to no higher than 6% of daily calories.

Did you know?

The term bacteria was devised in the 19th century by German biologist Ferdinand Cohn. He based it on the Greek word "bakterion" meaning a small rod or staff. Cohn is considered to be the father of modern bacteriology.

Did you know?

More than 20 million Americans cite use of marijuana within the past 30 days, according to the National Survey on Drug Use and Health (NSDUH). More than 8 million admit to using it almost every day.

Did you know?

Each year in the United States, there are approximately six million pregnancies. This means that at any one time, about 4% of women in the United States are pregnant.

For a complete list of videos, visit our video library