C# C# Basics (Retired) Perfect Integers and Doubles

Jiho Song
Jiho Song
16,469 Points

what is the answer?

I try to find the answer but couldnt after several attempts. what is the output?

Steven Parker
Steven Parker
170,320 Points

This quiz has 7 questions.

Which question is giving you trouble?

Jiho Song
Jiho Song
16,469 Points

Last one open question

1 Answer

Steven Parker
Steven Parker
170,320 Points

:point_right: Let's break it down into steps:

int a = 3;
int b = 2;
double c = 3.5;
double y = a / b * c;

Since multiply and divide have equal precedence and left-to-right associativity, the first thing that will happen is: a / b. These are both integers, and integer math produces integers, so: 3 / 2 = 1. Next, the 1 will be multiplied by 3.5, leaving it unchanged since it is a double and being assigned to a double. So the final result wil be: 3.5.

Be aware that some quizzes scramble the question order each time they are used, so it's always best to cut and paste the actual question to identify the one you are working with.

Jiho Song
Jiho Song
16,469 Points

Thanks now I understand!!