资源描述:
《Java(2章)答案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Chapter2ElementaryProgramming1.Valididentifiers:applet,Applet,$4,apps,x,y,radiusInvalididentifiers:a++,--a,4#R,#44,class,public,intKeywords:class,public,int2.doublemiles=100;finaldoubleKILOMETERS_PER_MILE=1.609;doublekilometers=KILOMETERS_PER_MILE*miles;System.out.println(kilomet
2、ers);Thevalueofkilometersis160.9.3.Therearethreebenefitsofusingconstants:(1)youdon’thavetorepeatedlytypethesamevalue;(2)thevaluecanbechangedinasinglelocation,ifnecessary;(3)theprogramiseasytoread.finalintSIZE=20;4.a=46/9;=>a=5a=46%9+4*4-2;=>a=1+16–2=15a=45+43%5*(23*3%2);=>a=45+3*
3、(1)=48a%=3/a+3;=>a%=3+3;a%=6=>a=a%6=1;d=4+d*d+4;=>4+1.0+4=9.0d+=1.5*3+(++a);=>d+=4.5+2;d+=6.5;=>d=7.5d-=1.5*3+a++;=>d-=4.5+1;=>d=1–5.5=-4.55.22-4-4016.(2+100)%7=4.SoitisThursday.7.Forbyte,from-128to127,inclusive.Forshort,from-32768to32767,inclusive.Forint,from-2147483648to2147483
4、647,inclusive.Forlong,from-9223372036854775808to9223372036854775807.Forfloat,thesmallestpositivefloatis1.40129846432481707e-45andthelargestfloatis3.40282346638528860e+38.Fordouble,thesmallestpositivedoubleis4.94065645841246544e-324andthelargestdoubleis1.79769313486231570e+308d.8.
5、25/4is6.Ifyouwantthequotienttobeafloating-pointnumber,rewriteitas25.0/4.0,25.0/4,or25/4.0.9.Yes,thestatementsarecorrect.Theprintoutis25/4is625/4.0is6.253*2/4is13.0*2/4is1.510.a.4.0/(3.0*(r+34))–9*(a+b*c)+(3.0+d*(2+a))/(a+b*d)11.1.0*m*(r*r)12.bandcaretrue.13.All.14.Line2:Missingst
6、aticforthemainmethod.Line2:stringshouldbeString.Line3:iisdefinedbutnotinitializedbeforeitisusedinLine5.Line4:kisanint,cannotassignadoublevaluetok.Lines7-8:Thestringcannotbebrokenintotwolines.15.longtotalMills=System.currentTimeMillis()returnsthemillisecondssinceJan1,1970.longtota
7、lSeconds=totalMills/1000returnsthetotalseconds.longtotalMinutes=totalSeconds/60returnsthetotalminutes.totalMinutes%60returnsthecurrentminute.16.Yes.Differenttypesofnumericvaluescanbeusedinthesamecomputationthroughnumericconversionsreferredtoascasting.17.Thefractionalpartistruncat
8、ed.Castingdoesnotchangethevariablebeingc