h h h h h h h h h h h
ch 4th Edition Reges h h h
Sample Midterm Exam #2
h h h
1. Expressions
Forheachhexpressionhinhthehleft-handhcolumn,hindicatehitshvaluehinhthehright-handhcolumn.
Behsurehtohlisthahconstanthofhappropriatehtypeh(e.g.,h7.0hratherhthanh7hforhahdouble,hStringshinhquotes).
Expression Value
h
8h+h5h*h3 / 2
h
1.5h*h4h* h+h3.4
73h%h10h- 6 % 10h+h28 % h3 h
4h+h1h+h9h+h"."h+h(-3h+h10)h+h11h/h3 h
3h/h14h/h7h/h(1.0h*h2)h+h10h/h6 h
10h>h11h==h4h/h3h>h1 h
1hofh8
mynursytest.store
,DOWNLOAD THE Test Bank for Building Java Programs Back to BasicsApproa
h h h h h h h h h h h
ch 4th Edition Regesh h h
2. ParameterhMystery
Aththehbottomhofhthehpage,hwritehthehoutputhproducedhbyhthehfollowinghprogram.
publichclasshParameterMysteryh{
publichstatichvoidhmain(String[]hargs)h{hSt
ringhxh=h"happy";
Stringhyh=h"pumpkin";hString
hzh=h"orange";hStringhpumpki
nh=h"sleepy";hStringhorangeh=
h"vampire";
orange(y,hx,hz);
orange(x,hz,hy);
orange(pumpkin,hz,h"y");hz
h=h"green";
orange("x",h"pumpkin",hz);ho
range(y,hz,horange);
}
publichstatichvoidhorange(Stringhz,hStringhy,hStringhx)h{hSystem.out.println(yh+h"h
andh"h+hzh+h"hwereh"h+hx);
}
}
2hofh8
mynursytest.store
, DOWNLOAD THE Test Bank for Building Java Programs Back to BasicsApproa
h h h h h h h h h h h
ch 4th Edition Reges h h h
3. If/ElsehSimulation
Forheachhcallhofhthehmethodhbelow,hwritehthehvaluehthathishreturned:
publichstatichinthmystery(inthn)h{hifh
(nh<h0)h{
nh=hnh*h3;hre
turnhn;
}helseh{
nh=hnh+h3;
}
ifh(nh%h2h==h1)h{
nh=hnh+hnh%h10;
}
returnhn;
}
MethodhCall ValuehReturned
mystery(-5) h
mystery(0) h
mystery(7) h
mystery(18) h
mystery(49) h
3hofh8
mynursytest.store