资源描述:
《java考试题带答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、第一章复习题1.4Sourceprogrammeanstheoriginalprogramwritteninahigh-levellanguage・Acompilerisaprogramthattranslatessourceprogramintoexecutablecode・1.7DevelopedbyateamledbyJamesGoslingatSunMicrosystemsin1991・OriginallycalledOak,itbecameJavain1995whenitwasredesignedfordevelopingInternetapplications.1.11
2、Keywordshavespec讦icmeaningtothecompilerandcannotbeusedforotherpurposesintheprogramsuchasvariablesormethodnames・Examplesofkeywordsareclass,static,andvoid.1.12Javasourcecodeiscasesensitive.Javakeywordsarealwaysinlowercase・1.13Thesourcefileextensionis.javaandthebytecodefileextensionis.class.1.16p
3、ublicclassWelcome{publicstaticvoidmein(String[]args){System.out•print丄n(HmorningH);System,out"afternoon");i1.17Line2.Mainshouldbemain.Line2.staticismissing.Line3:WelcometoJava!shouldbeenclosedinsidedoublequotationmarks・Line5:Thelast)shouldbe}.1.18javacistheJDKcommandtocompileaprogram,javaisthe
4、JDKcommandtorunaprogram.1.19Javainterpretercannotfindthe・classfile・Makesureyouplacedthe・classintherightplace,andinvokedjavacommandwithappropriatepackagename・1.20Theclassdoesnothaveamainmethod,orthesignatureofthemainmethodisincorrect.编程题1-6publicclassExercisel_6{publicstaticvoidmain(String[]arg
5、s){System.out.println(l+2+3+4+5+6+7+8+9);}}1-7publicclassExercisel_7{publicstaticvoidmain(String[]args){System.out.println(4*(1-1.0/3+1.0/5・1.0/7+1.0/9・1.0/11+1.0/13));}}第二章复习题2.1Valididentifiers:applet,Applet,$4,apps,x,y,radiusInvalididentifiers:a++,-a,4#R,#44,class,public,intKeywords:class,p
6、ublic,int2.14Line2:Missingstaticforthemainmethod.Line2:stringshouldbeString.Line3:iisdefinedbutnotinitializedbeforeitisusedinLine5.Line4:kisanint,cannotassignadoublevaluetok・Lines7-8:Thestringcannotbebrokenintotwolines.2.24bc-22.25System.out.println("l"+1);=>11System.out.printlnCl'+1);=>50(sin
7、cetheUnicodefor1is49System.out.println("l"+1+1);=>111System.out.println("l"+(1+1));=>12System.out.println('l'+1+1);=>51编程练习2.2importjava.util.Seanner;publicclassExercise2_2{publicstaticvoidmain(String[]args){Scannerinput=newScanner(Syst