1书后习题参考答案习题1............................................................................................................................................2习题2............................................................................................................................................3习题3............................................................................................................................................4习题4..........................................................................................................................................10习题5...........................................................................................................................................11习题6..........................................................................................................................................14习题7..........................................................................................................................................15习题9..........................................................................................................................................16习题12........................................................................................................................................20习题13........................................................................................................................................25习题14........................................................................................................................................27习题15........................................................................................................................................28习题16........................................................................................................................................31习题17........................................................................................................................................392习题11.JamesGosling2.(1)使用一个文本编辑器编写源文件。(2)使用Java编译器(javac.exe)编译Java源程序,得到字节码文件。命令:javac–d.文件名称.java(3)使用Java解释器(java.exe)运行Java程序。命令:java包名.类名3.Java的源文件是由若干个书写形式互相独立的类、接口、枚举等组成。应用程序中可以没有public类,若有的话至多可以有一个public类。4.新建JAVA_HOME系统环境变量,指向安装目录在系统环境变量path中增加内容:%JAVA_HOME%\bin;新建系统环境变量classpath并填入三项:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar5.B6.Java源文件的扩展名是.java。Java字节码的扩展名是.class。7.D8.(1)Speak.java(2)生成两个字节码文件,这些字节码文件的名字Speak.class和Xiti8.class(3)javaXiti8(4)执行javaSpeak的错误提示Exceptioninthreadmainjava.lang.NoSuchMethodError:main执行javaxiti8得到的错误提示Exceptioninthreadmainjava.lang.NoClassDefFoundError:xiti8(wrongname:Xiti8)执行javaXiti8.class得到的错误提示Exceptioninthreadmainjava.lang.NoClassDefFoundError:Xiti8/class执行javaXiti8得到的输出结果I'mgladtomeetyou9.属于操作题,解答略。3习题21.BD2.【代码1】【代码2】错误//【代码3】更正为floatz=6.89F;3.float型常量后面必须要有后缀“f”或“F”。对于double常量,后面可以有后缀“d”或“D”,但允许省略该后缀。4.publicclassXiti4{publicstaticvoidmain(Stringargs[]){charch1='你',ch2='我',ch3='他';System.out.println(\+ch1+\的位置:+(int)ch1);System.out.println(\+ch2+\的位置:+(int)ch2);System.out.println(\+ch3+\的位置:+(int)ch3);}}5.数组名字.length6.数组名字.length7.【代码1】A,65【代码2】-127【代码3】123456.783,123456.783128.【代码1】false【代码2】true【代码3】false【代码4】3【代码5】4.4【代码6】8.84习题31.输出110if-else语句书写的不够规范,复合语句缺少大括号“{}”,代码不够清晰。2.你好好酷!!3.publicclassXiti3_3{publicstaticvoidmain(Stringargs[]){intstartPosition=0,endPosition=0;charcStart='а',cEnd='я';startPosition=(int)cStart;//cStart做int型转换,结果赋给startPositionendPosition=(int)cEnd;//cEnd做int型转换运算,结果赋给endPositionSystem.out.println(俄文字母表:);for(inti=startPosition;i=endPosition;i++){charc='\0';c=(char)i;//i做char型转换运算,并将结果赋值给cSystem.out.print(+c);//System.out.print(+c++Integer.toHexString(c));if((i–startPosition+1)%10==0){System.out.println();}}}}4.随书给出的解答:publicclassXiti4{publicstaticvoidmain(Stringargs[]){doublesum=0,a=1;inti=1;while(i=20){sum=sum+a;i++;a=a*i;}System.out.println(sum=+sum);}}结果:sum=2.5613274941118203E18如果sum改成long的情况???1!=12!=23!=64!=245!=1206!=7207!=50408!=403209!=36288010!=362880011!=3991680012!=47900160013!=622702080014!=8717829120015!=130767436800016!=2092278988800017!=35568742809600018!=640237370572800019!=12164510040883200020!=2432902008176640000sum=2561327494111820313262412072050404032036288036288003991680047900160062270208008717829120013076743680002092278988800035568742809600064023737057280001216451004088320002432902008176640000-4249290049419214848sum=25613274941118203135精确计算的方法:[书P201有类似操作]BigIntegersum=newBigInteger(0);BigIntegerfactorial=newBigInteger(1);for(inti=0;i20;){i++;factorial=factorial.multiply(newBigInteger(String.valueOf(i)));System.out.println(i+!=+factorial);sum=sum.add(factorial);}System.out.println(sum=+sum);//256-1327-4941-1182-0313//System.out.println(Long.MAX_VALUE);922-3372-0368-5477-58075.classXiti5{publicstaticvoidmain(Stringargs[]){for(intj=2;j=100;j++){inti=0;for(i=2;i=j/2;i++){if(j%i==0)break;}if(ij/2){System.out.print(+j);}}}}6.classXiti6{publicstaticvoidmain(Stringargs[]){doublesum=0;doublereciprocalFactorial=1;for(inti=1;i=20;i++){rec