Lecture 2

Lecture 2 - Practice Quiz 1 in Week 2 (Answers) 1. What...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Practice Quiz 1 in Week 2 (Answers) 1. What will be the final value stored in the variable result ? a. int result; result = 3 + 3*4 +3; 18 b. int result = 3; result = 3 + 4/result; 4 c. int result = 3; result = 3 + 8%result; 5 d .int a=3, b=4, result=5; result += a; 8 e. int a=3, b=4, result=5; result *= a; 15 f. int a=3, b=4, result=5; result++; 6 g. int a=3, b=4, result=5; result = ++a + b++; 8 h. int a=3, b=4, result=5; result = ++a + ++b; 9 i. int result = 10; if(result < 100) result = 200; 200 j. double result = 10.0; result = result/4; 2.50 2. Complete this code to find the maximum m of three numbers a, b and c. double m, a = 3.1, b = 5.6, c = 4.2; m = Math.max(a,b); m = Math.max(m,c); 3. Complete this code to calculate the hypotenuse of a right-angled triangle. double hypotenuse, base=4, height = 5; hypotenuse = Math.sqrt(base*base + height*height);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example of Making Change from Chapter 2 Calculate the number of quarters, dimes and nickels and pennies to give a person if their change due is n cents, where n runs from 1 to 99. This is a beautiful example illustrating the sue of the % operator and is highly recommended for exam study.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/17/2012 for the course ECE 203 taught by Professor Robincarr during the Fall '07 term at Drexel.

Page1 / 5

Lecture 2 - Practice Quiz 1 in Week 2 (Answers) 1. What...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online