资源描述:
《java考试题带答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第一章复习题1.4Sourceprogrammeanstheoriginalprogramwritteninahigh-levellanguage.Acompilerisaprogramthattranslatessourceprogramintoexecutablecode.1.7DevelopedbyateamledbyJamesGoslingatSunMicrosystemsin1991.OriginallycalledOak,itbecameJavain1995whenitwasredesignedfordevelopingInte
2、rnetapplications.1.11Keywordshavespecificmeaningtothecompilerandcannotbeusedforotherpurposesintheprogramsuchasvariablesormethodnames.Examplesofkeywordsareclass,static,andvoid.1.12Javasourcecodeiscasesensitive.Javakeywordsarealwaysinlowercase.1.13Thesourcefileextensionis.ja
3、vaandthebytecodefileextensionis.class.1.16publicclassWelcome{publicstaticvoidmain(String[]args){System.out.println("morning");System.out.println("afternoon");}}1.17Line2.Mainshouldbemain.Line2.staticismissing.Line3:WelcometoJava!shouldbeenclosedinsidedoublequotationmarks.L
4、ine5:Thelast)shouldbe}.1.18javacistheJDKcommandtocompileaprogram.javaistheJDKcommandtorunaprogram.1.19Javainterpretercannotfindthe.classfile.Makesureyouplacedthe.classintherightplace,andinvokedjavacommandwithappropriatepackagename.1.20Theclassdoesnothaveamainmethod,orthesi
5、gnatureofthemainmethodisincorrect.编程题1-6publicclassExercise1_6{publicstaticvoidmain(String[]args){System.out.println(1+2+3+4+5+6+7+8+9);}}1-7publicclassExercise1_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.
6、1Valididentifiers:applet,Applet,$4,apps,x,y,radiusInvalididentifiers:a++,--a,4#R,#44,class,public,intKeywords:class,public,int2.14Line2:Missingstaticforthemainmethod.Line2:stringshouldbeString.Line3:iisdefinedbutnotinitializedbeforeitisusedinLine5.Line4:kisanint,cannotassi
7、gnadoublevaluetok.Lines7-8:Thestringcannotbebrokenintotwolines.2.24bc-22.25System.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);=>51编程练习2.2importja
8、va.util.Scanner;publicclassExercise2_2{publicstaticvoidmain(String[]args){Scannerinput=ne