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(kilometers);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*(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-2147483648to2147483647,inclusive.Forlong,from-9223372036854775808to9223372036854775807.Forfloat,thesmallestpositivefloatis1.40129846432481707e-45andthelargestfloatis3.40282346638528860e+38.Fordouble,thesmallestpositivedoubleis4.94065645841246544e-324andthelargestdoubleis1.79769313486231570e+308d.8.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:Missingstaticforthemainmethod.Line2:stringshouldbeString.Line3:iisdefinedbutnotinitializedbeforeitisusedinLine5.Line4:kisanint,cannotassignadoublevaluetok.Lines7-8:Thestringcannotbebrokenintotwolines.15.longtotalMills=System.currentTimeMillis()returnsthemillisecondssinceJan1,1970.longtotalSeconds=totalMills/1000returnsthetotalseconds.longtotalMinutes=totalSeconds/60returnsthetotalminutes.totalMinutes%60returnsthecurrentminute.16.Yes.Differenttypesofnumericvaluescanbeusedinthesamecomputationthroughnumericconversionsreferredtoascasting.17.Thefractionalpartistruncated.Castingdoesnotchangethevariablebeingcast.18.fis12.5iis1219.System.out.println((int)'1');System.out.println((int)'A');System.out.println((int)'B');System.out.println((int)'a');System.out.println((int)'b');System.out.println((char)40);System.out.println((char)59);System.out.println((char)79);System.out.println((char)85);System.out.println((char)90);System.out.println((char)0X40);System.out.println((char)0X5A);System.out.println((char)0X71);System.out.println((char)0X72);System.out.println((char)0X7A);20.'\u345dE'iswrong.Itmusthaveexactlyfourhexnumbers.21.'\\'and'\”'22.ibecomes49,sincetheASCIIcodeof'1'is49;jbecome99since(int)'1'is49and(int)'2'is50;kbecomes97sincetheASCIIcodeof'a'is97;cbecomescharacter'z'since(int)'z'is90;23.charc='A';i=(int)c;//ibecomes65floatf=1000.34f;inti=(int)f;//ibecomes1000doubled=1000.34;inti=(int)d;//ibecomes1000inti=97;charc=(char)i;//cbecomes'a'24.bc-225.System.out.println(1+1);=11System.out.println('1'+1);=50(sincetheUnicodefor1is49System.out.println(1+1+1);=111System.out.println(1+(1+1));=12System.out.println('1'+1+1);=5126.1+Welcome+1+1is1Welcome11.1+Welcome+(1+1)is1Welcome2.1+Welcome+('\u0001'+1)is1Welcome21+Welcome+'a'+1is1Welcomea127.Classnames:Capitalizethefirstletterineachname.Variablesandmethodnames:Lowercasethefirstword,capitalizethefirstletterinallsubsequentwords.Constants:Capitalizeallletters.28.publicclassTest{/**Mainmethod*/publicstaticvoidmain(String[]args){//PrintalineSystem.out.println(2%3=+2%3);}}29.Compilationerrorsaredetectedbycompilers.Runtimeerrorsoccurduringexecutionoftheprogram.Logicerrorsresultsinincorrectresults.30.TheMathclassisinthejava.langpackage.Anyclassinthejava.langpackageisautomaticallyimported.Sothereisnoneedtoimportitexplicitly.31.Strings=JOptionPane.showInputDialog(“Enteraninput”);32.inti=Integer.parseInt(s);doubles=Double.parseDouble(s);