Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJiho Song
16,469 Pointswhat is the answer?
I try to find the answer but couldnt after several attempts. what is the output?
Jiho Song
16,469 PointsLast one open question
1 Answer
Steven Parker
231,236 PointsLet'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
16,469 PointsThanks now I understand!!
Steven Parker
231,236 PointsSteven Parker
231,236 PointsThis quiz has 7 questions.
Which question is giving you trouble?