Java大学基础教程(英文第六版)课后第六章自测题答案

合集下载

《Java基础入门》-课后习题答案--1-6

《Java基础入门》-课后习题答案--1-6

第1章Java开发入门一、填空题1、Java EE、Java SE、Java ME2、JRE3、javac4、bin5、path、classpath二、选择题1、ABCD2、C3、D4、B5、B三、简答题1、面向对象、跨平台性、健壮性、安全性、可移植性、多线程性、动态性等。

2、JRE(Java Runtime Environment,Java运行时环境),它相当于操作系统部分,提供了Java程序运行时所需要的基本条件和许多Java基础类,例如,IO类、GUI控件类、网络类等。

JRE是提供给普通用户使用的,如果你只想运行别人开发好的Java程序,那么,你的计算机上必须且只需安装JRE。

JDK(Java Development Kit,Java开发工具包),它包含编译工具、解释工具、文档制作工具、打包工具多种与开发相关的工具,是提供给Java开发人员使用的。

初学者学习和使用Java语言时,首先必须下载和安装JDK。

JDK中已经包含了JRE部分,初学者安装JDK后不必再去下载和安装JRE了。

四、编程题public class HelloWorld {public static void main(String[] args) {System.out.println("这是第一个Java程序!");}}第2章Java编程基础一、填空题1、class2、true和false3、单行注释、多行注释、文档注释4、基本数据类型、引用数据类型5、1、2、4、86、& && | ||7、08、59、3410、56二、判断题1、错2、对3、错4、对5、错三、选择题1、AD2、AD3、C4、ABCD5、C 6 、A 7、AC 8、A 9、B 10、A四、程序分析题1、编译不通过。

int值4和b相加时,由于变量b的类型为byte,取值范围没有int类型大,存不下int类型的值,因此编译不通过。

java语言程序设计第6章

java语言程序设计第6章
同父类的异常统一处理,也可区分不同的异常分别处理,使用非常灵活。
第6章 常见错误和异常处理
6.2.2 Exception类
Java语言的异常类是处理运行时错误的特殊类,每一种异常类对应一种特定 的运行错误。所有的Java异常类都是系统类库中的Exception类的子类 。 Exception类有若干子类,每一个子类代表了一种特定的运行时错误。这些 子类有些是系统事先定义好并包含在Java类库中的,称为系统定义的运行异 常。 系统定义的运行异常通常对应着系统运行错误。由于这种错误可能导致操作 系统错误甚至是整个系统的瘫痪,所以需要定义异常类来特别处理。 常见的系统定义异常如下: (1)ArithmeticException:数学错误。 (2)ArrayIndexOutOfBoundsException:数组下标越界使用。 (3)ClassNotFoundException:未找到欲使用的类。 (4)FileNotFoundException:未找到指定的文件或目录。
第6章 常见错误和异常处理
6.2.4 多异常的处理
如果所有的catch语句都不能与当前的异常对象匹配,则说明当前方法不能 处理这个异常对象,程序流程将返回到调用该方法的上层方法。如果这个上 层方法中定义了与所产生的异常对象相匹配的catch语句,流程就跳转到这 个catch语句中,否则将继续回溯更上层的方法。 如果所有的方法中都找不到合适的catch语句,则由Java运行系统来处理这 个异常对象。此时通常会中止程序的执行,退出虚拟机返回操作系统,并在 标准输出上打印相关的异常信息。 如果try语句体中所有语句的执行都没有引发异常,则所有的catch语句体都 会被忽略而不予执行。 catch语句体中的语句应根据异常的不同而执行不同的操作,比较通用的操 作是打印异常和错误的相关信息,包括异常名称、产生异常的方法名等。 由于异常对象与catch语句的匹配是按照catch语句的先后排列顺序进行的, 所以在处理多异常时应注意认真设计各catch语句的排列顺序。一般来说, 将处理较具体和较常见的异常的catch语句应放在前面,而可以与多种异常 相匹配的catch语句应放在较后的位置。此外,不能将子类异常的catch语句 放在父类的后面,否则在编译时会产生错误。

java答案第六章

java答案第六章

Java语言程序设计第六章课后习题答案1.将本章例6-1至6-18中出现的文件的构造方法均改为使用File类对象作为参数实现。

个人理解:File类只能对整文件性质进行处理,而没法通过自己直接使用file.Read()或者是file.write()类似方法对文件内容进行写或者读取。

注意:是直接;下面只提供一个例2变化,其他的你自己做,10几道啊,出这题的人真他妈有病。

import java.io.*;public class test6_2{public static void main(String[] args) throws IOException { String fileName = "D:\\Hello.txt";File writer=new File(fileName);writer.createNewFile();BufferedWriter input = new BufferedWriter(newFileWriter(writer));input.write("Hello !\n");input.write("this is my first text file,\n");input.write("你还好吗?\n");input.close();}}运行结果:(电脑系统问题,没法换行,所以一般使用BuffereWriter中newLine()实现换行)2.模仿文本文件复制的例题,编写对二进制文件进行复制的程序.// CopyMaker类import java.io.*;class CopyMaker {String sourceName, destName;BufferedInputStream source;BufferedOutputStream dest;int line;//打开源文件和目标文件,无异常返回trueprivate boolean openFiles() {try {source = new BufferedInputStream(newFileInputStream( sourceName ));}catch ( IOException iox ) {System.out.println("Problem opening " + sourceName );return false;}try {dest = new BufferedOutputStream(newFileOutputStream( destName ));}catch ( IOException iox ){System.out.println("Problem opening " + destName );return false;}return true;}//复制文件private boolean copyFiles() {try {line = source.read();while ( line != -1 ) {dest.write(line);line = source.read();}}catch ( IOException iox ) {System.out.println("Problem reading or writing" );return false;}return true;}//关闭源文件和目标文件private boolean closeFiles() {boolean retVal=true;try { source.close(); }catch ( IOException iox ) {System.out.println("Problem closing " + sourceName );retVal = false;}try { dest.close(); }catch ( IOException iox ) {System.out.println("Problem closing " + destName );retVal = false;}return retVal;}//执行复制public boolean copy(String src, String dst ) {sourceName = src ;destName = dst ;return openFiles() && copyFiles() && closeFiles();}}//test6_2public class test6_2{public static void main ( String[] args ) {String s1="lin.txt",s2="newlin.txt";if(new CopyMaker().copy(s1, s2))S ystem.out.print("复制成功");elseS ystem.out.print("复制失败");}}运行前的两个文本:lin.txt和newlin.txt(为空)运行后:3.创建一存储若干随机整数的文本文件,文件名、整数的个数及范围均由键盘输入。

《Java语言程序设计:基础篇》课后复习题答案-第六章

《Java语言程序设计:基础篇》课后复习题答案-第六章

《Java语言程序设计:基础篇》课后复习题答案-第六章Chapter6Single-dimensional Arrays1.See the section"Declaring and Creating Arrays."2.You access an array using its index.3.No memory is allocated when an array is declared.The memory is allocated whencreating the array.x is60The size of numbers is304.Indicate true or false for the following statements:1.Every element in an array has the same type.Answer:True2.The array size is fixed after it is declared.Answer:False3.The array size is fixed after it is created.Answer:True4.The element in the array must be of primitive data type.Answer:False5.Which of the following statements are valid array declarations?int i=new int(30);Answer:Invaliddouble d[]=new double[30];Answer:Validchar[]r=new char(1..30);Answer:Invalidint i[]=(3,4,3,2);Answer:Invalidfloat f[]={2.3, 4.5, 5.6};Answer:Validchar[]c=new char();Answer:Invalid6.The array index type is int and its lowest index is0.a[2]7.(a)double[]list=new double[10];(b)list[list.length–1]=5.5;(c)System.out.println(list[0]+list[1]);(d)double sum=0;for(int i=0;i<list.length;i++)< p="">sum+=list[i];(e)double min=list[0];for(int i=1;i<list.length;i++)< p="">if(min>list[i])min=list[i];(f)System.out.println(list[(int)(Math.random()*list.length));(g)double[]={3.5, 5.5, 4.52, 5.6};8.A runtime exception occurs.9.Line3:the array declaration is wrong.It should be double[].The array needs tobe created before its been used.e.g.new double[10]Line5:The semicolon(;)at the end of the for loop heading should be removed.Line5:r.length()should be r.length.Line6:random should be random()Line6:r(i)should be r[i].10.System.arraycopy(source,0,t,0,source.length);11.The second assignment statement myList=new int[20]creates a new array andassigns its reference to myList.myList new int[10]Array myList new int[10]Arraynew int[20]Array12.False.When an array is passed to a method,the reference value of the array ispassed.No new array is created.Both argument and parameter point to the samearray.13.numbers is 0and numbers[0]is314.(A) ExecutingcreateArray in Line 6Space required for the main methodchar[] chars: refHeap Array of 100 charactersSpace required for the createArray methodchar[] chars: ref(B) After exitingcreateArray in Line 6Space required for themain methodchar[] chars: refHeapArray of 100charactersStack Stack (C) ExecutingdisplayArray in Line 10Space required for the main methodchar[] chars: refHeap Array of 100 charactersSpace required for the displayArray method char[] chars: ref(D) After exitingdisplayArray in Line10Space required for themain methodchar[] chars: refHeapArray of 100charactersStack Stack(E) Executing countLetters in Line 13 Space required for the main methodint[] counts: refchar[] chars: refHeap Array of 100 charactersSpace required for the countLetters method int[] counts: refchar[] chars: ref (F) After exitingcountLetters in Line 13Space required for themain methodint[] counts: refchar[] chars: refHeapArray of 100charactersStack StackArray of 26 integers Array of 26 integers(G) Executing displayCounts in Line 18Space required for the main methodint[] counts: refchar[] chars: refHeap Array of 100 charactersSpace required for the displayCounts methodint[] counts: ref (H) After exitingdisplayCounts in Line 18Space required for themain methodint[] counts: refchar[] chars: refHeapArray of 100charactersStack StackArray of 26 integers Array of 26 integers15.Only one variable-length parameter may be specified ina method and this parameter must be the last parameter.The method return type cannot be a variable-length parameter.16.The last oneprintMax(new int[]{1,2,3});is incorrect,because the array must of the double[] type.17.Omitted18.Omitted19.Omitted20Simply change(currentMaxlist[j])21Simply change list[k]>currentElement on Line9tolist[k]<currentelement< p="">22.You can sort an array of any primitive types except boolean.The sort method is void,so it does not return a new array.23.To apply java.util.Arrays.binarySearch(array,key),the array must be sorted in increasing order.24.Line1:list is{2,4,7,10}Line2:list is{7,7,7,7}Line3:list is{7,8,8,7}Line4:list is{7,8,8,7}</currentelement<></list.length;i++)<></list.length;i++)<>。

java程序设计教程(第六版)课后习题答案

java程序设计教程(第六版)课后习题答案

pp2.3public class fudian {public static void main(String[] args) {float a=2.10f,b=3.70f;float Result1,Result2,Result3;Result1=a+b;Result2=a-b;Result3=a*b;System.out.println("Result1 is:"+Result1);System.out.println("Result2 is:"+Result2);System.out.println("Result3 is:"+Result3);}}2.4public class TempConverter {public static void main(String[] args) {final int BASE = 32;final double CONVERSION_FACTOR = 5.0 / 9.0;double celsiusTemp;int fahrenheitTemp = 70; // value to convertcelsiusTemp = (fahrenheitTemp - BASE)*CONVERSION_FACTOR;System.out.println ("Fahrenheit Equivalent: " + fahrenheitTemp);System.out.println ("Celsius Temperature: " + celsiusTemp);}}2.5public class yinglizhuanqianmi {public static void main(String[] args) {float Base=1.60935f;float Qianmi;float Yingli=19.85f;Qianmi=Yingli*Base;System.out.println ("Ying Li: " + Yingli);System.out.println ("Qian Mi: " +Qianmi);}}2.6public class TimeConverter1 {public static void main(String[] args) {int Hour=5,Minute=35,Second=51;int SECONDS;SECONDS=Hour*60*60+Minute*60+Second;System.out.println (+Hour+"时"+Minute+"分"+Second+"秒");System.out.println ("换算成秒: " + SECONDS);}}2.7public class TimeConverter2 {public static void main(String[] args) {int SECONDS=10853;int Hour,Minute,Second;Second=SECONDS%60;Minute=(SECONDS-Second)%60;Hour=(SECONDS-Second-Minute*60)/3600;System.out.println (SECONDS+"秒,转化为");System.out.println (Hour+"时"+Minute+"分"+Second+"秒");}}2.9import java.util.*;public class Dollarbill {public static void main(String[] args) {float Dollar1,Dollar2;int Ten,Five,One,Quarters,Dimes,Nickles,Pennies;Scanner reader=new Scanner(System.in);System.out.println("输入币值:");Dollar1=reader.nextFloat();Dollar2=Dollar1*100;Pennies= (int)Dollar2%5;Nickles=((int)Dollar2%10-Pennies)/5;Dimes=((int)Dollar2-Pennies-Nickles*5)%50/10;Quarters=(int)Dollar2%100/50;One=((int)Dollar2- Pennies-Nickles*5-Dimes*10-Quarters*50)%500/100;Five=(int)Dollar2%1000/500;Ten=(int)Dollar2/1000;System.out.println(Ten+ "ten dollar bills");System.out.println(Five+ " five dollar bills");System.out.println(One+ "one dollar bills");System.out.println(Quarters+ "quarters dollar bills");System.out.println(Dimes+ "dimes dollar bills");System.out.println(Nickles+ "nickles dollar bills");System.out.println(Pennies+ "pennies dollar bills!");}}2.11import java.util.*;public class Fenshuzhuanhuan {public static void main(String[] args) {int x,y;double Result=0;Scanner reader=new Scanner(System.in);System.out.println("输入x:");x=reader.nextInt();System.out.println("输入y:");y=reader.nextInt();Result+=x/y;System.out.println ("分数"+x+"/"+y);System.out.println ("转换成小数是: " + Result);}}2.16import javax.swing.JApplet;import java.awt.*;public class Olympiclogo extends JApplet{public void paint (Graphics page) {page.setColor(Color.blue);page.drawOval(25, 65, 40, 40);page.setColor(Color.yellow);page.drawOval (55, 65, 40, 40);page.setColor(Color.black);page.drawOval (85, 65, 40, 40);page.setColor(Color.green);page.drawOval (115, 65, 40, 40);page.setColor(Color.red);page.drawOval (145, 65, 40, 40);// circlepage.setColor(Color.cyan);page.drawString ("OL YMPIC LOGO", 40, 30);}}2.19import java.applet.*;import java.awt.*;public class Ex2_19 extends Applet{public void paint (Graphics page){page.setColor(Color.BLACK);page.setFont(new Font("楷体",Font.ITALIC+Font.BOLD,30));page.drawString ("林少锋", 40, 30);page.setColor(Color.blue);page.setFont(new Font("宋体",Font.BOLD,30));page.drawString ("林少锋", 70, 80);}}2.20import java.applet.*;import java.awt.*;public class Ex2_20 extends Applet{public void paint (Graphics page){page.drawOval(35, 35, 130, 130);page.setColor(Color.red);page.fillArc(35, 35, 130, 130,0,45);page.setColor(Color.blue);page.fillArc(35, 35, 130, 130,45,45);page.setColor(Color.yellow);page.fillArc(35, 35, 130, 130,90,45);page.setColor(Color.cyan);page.fillArc(35, 35, 130, 130,135,45);page.setColor(Color.gray);page.fillArc(35, 35, 130, 130,180,45);page.setColor(Color.green);page.fillArc(35, 35, 130, 130,225,45);page.setColor(Color.darkGray);page.fillArc(35, 35, 130, 130,270,45);page.setColor(Color.pink);page.fillArc(35, 35, 130, 130,315,45);}}PP4.1方法1import java.util.*;public class CreateSphere {/*** @param args*/public static void main(String[] args) {// TODO 自动生成方法存根System.out.println("请输入直径d:");Scanner scan=new Scanner(System.in);double d=scan.nextDouble();Sphere D=new Sphere(d);D.Square();D.Volum();System.out.println(D.toString());}}public class Sphere {final double PI=3.14;double V,S;double d;Sphere(double d){this.d=d;}public void V olum(){V=(4/3)*PI*(d/2)*(d/2)*(d/2);}public void Square(){S=4*PI*(d/2)*(d/2);}public String toString(){String s="";String result1=Double.toString(S);String result2=Double.toString(V);s=("体积为:"+result2+"面积为:"+result1);return s;}}方法2//Sphere.javapublic class Sphere{private double diameter;public Sphere(){//构造方法:无参数this.diameter = 1.0;}public Sphere(double d){ //构造方法:带一个参数this.diameter = d;}public void setDiameter(double d) {//设置直径值的方法this.diameter = d;}public double getDiameter(){//获取直径值的方法return this.diameter;}public double volume(){//计算球的体积return 4*Math.PI*Math.pow(this.diameter/2,3)/3;}public double area(){//计算球的表面积return 4*Math.PI*Math.pow(this.diameter/2,2);}public String toString(){String out = "该球体的直径为:" + this.diameter + "\n" + "该球体的表面积为:" + this.area() + "\n" +"该球体的体积为:" + this. volume();return out;}}//MultiSphere.javaimport java.util.Scanner;public class MultiSphere{public static void main(String[] args){Scanner scan = new Scanner(System.in);Sphere sphere1 = new Sphere();Sphere sphere2 = new Sphere(3.5);System.out.println("sphere1: " + sphere1 + "\n");System.out.println("sphere2: " + sphere2 + "\n");System.out.println("sphere1和sphere2分别调用无参构造方法" +"和带一个参数的构造方法进行初始化。

Java大学基础教程(英文第六版)课后第六章自测题答案

Java大学基础教程(英文第六版)课后第六章自测题答案

//test the 'Math' class//Math class is a part of ng package, so no need to import it publicclass p217_6$3 {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubSystem.out.printf("Math.abs( 23.7 ) = %s\n", Math.abs( 23.7 ) );System.out.printf("Math.abs( 23.7 ) = %f\n", Math.abs( 23.7 ) );System.out.printf("Math.abs( 0.0 ) = %f\n", Math.abs( 0.0 ) );System.out.printf("Math.abs( -23.7 ) = %f\n", Math.abs( -23.7 ) );System.out.printf("Math.ceil( 9.2 ) = %f\n", Math.ceil( 9.2 ) );System.out.printf("Math.ceil( -9.8 ) = %f\n", Math.ceil( -9.8 ) );System.out.printf("Math.cos( 0.0 ) = %f\n", Math.cos( 0.0 ) );System.out.printf("Math.exp( 1.0 ) = %f\n", Math.exp( 1.0 ) );System.out.printf("Math.exp( 2.0 ) = %f\n", Math.exp( 2.0 ) );System.out.printf("Math.floor( 9.2 ) = %f\n", Math.floor( 9.2 ) );System.out.printf("Math.floor( -9.8 ) = %f\n",Math.floor( -9.8 ) );System.out.printf("Math.log( Math.E ) = %f\n",Math.log(Math.E ) );System.out.printf("Math.log( Math.E * Math.E ) = %f\n",Math.log(Math.E * Math.E ) );System.out.printf("Math.max( 2.3, 12.7 ) = %f\n",Math.max( 2.3, 12.7 ) );System.out.printf("Math.max( -2.3, -12.7 ) = %f\n",Math.max( -2.3, -12.7 ) );System.out.printf("Math.min( 2.3, 12.7 ) = %f\n",Math.min( 2.3, 12.7 ) );System.out.printf("Math.min( -2.3, -12.7 ) = %f\n",Math.min( -2.3, -12.7 ) );System.out.printf("Math.pow( 2.0, 7.0 ) = %f\n",Math.pow( 2.0, 7.0 ) );System.out.printf("Math.pow( 9.0, 0.5 ) = %f\n",Math.pow( 9.0, 0.5 ) );System.out.printf("Math.sin( 0.0 ) = %f\n", Math.sin( 0.0 ) );System.out.printf("Math.sqrt( 900.0 ) = %f\n",Math.sqrt( 900.0 ) );System.out.printf("Math.tan( 0.0 ) = %f\n", Math.tan( 0.0 ) );}}import java.util.Scanner;publicclass p218_6$6a {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input the radius of a sphere:\n");double r = input.nextDouble();p218_6$6b compute = new p218_6$6b();//compute areadouble area = puteArea(r);System.out.printf("\nthe AREA of a sphere is: %f\n", area);//compute volumedouble volume = puteVolume(r);System.out.printf("\nthe VOLUME of a sphere is: %f\n", volume);}}publicclass p218_6$6b {publicdouble computeArea(double r){double area = Math.PI * Math.pow(r, 2) ;return area;}publicdouble computeVolume(double r){double volume = (4/3) * Math.PI * Math.pow(r, 3);return volume;}}publicclass p220_6$7 {publicstaticvoid main(String[] args) {// TODO Auto-generated method stubSystem.out.printf("x = Math.abs( 7.5 ), x=%s\n", Math.abs(7.5));System.out.printf("x = Math.floor( 7.5 ) , x=%s\n", Math.floor(7.5));System.out.printf("x = Math.abs( 0.0 ) , x=%s\n", Math.abs(0.0));System.out.printf("x = Math.ceil( 0.0 ) , x=%s\n", Math.ceil(0.0));System.out.printf("x = Math.abs( -6.4 ) , x=%s\n", Math.abs(-6.4));System.out.printf("x = Math.ceil( -6.4 ) , x=%s\n", Math.ceil(-6.4));System.out.printf("x = Math.ceil( -Math.abs( -8 + Math.floor( -5.5 ) ) ), x=%s\n",Math.ceil(-Math.abs(-8 + Math.floor(-5.5))));}}import java.util.*;publicclass p221_6$8 {publicvoid caculateCharges(double in){if (in <= 3) {double totalcost=2;System.out.printf("the total cost is %.2f\n", totalcost);}elseif (in > 3 && in <=24 ){double totalcost = 2 + (in - 3) * 0.5;if (totalcost> 10)totalcost =10;System.out.printf("the total cost is %.2f\n", totalcost);}else{System.out.print("an illegal input time");}}publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input the total parking time( <= 24 hour):\n");double inputn = input.nextDouble();//double totalcost = 0;p221_6$8 time = new p221_6$8();time.caculateCharges(inputn);}}publicclass P221_6$9 {publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input a double number!\n");double x = input.nextDouble();int y = (int) Math.floor(x);if (x-y<0.5){System.out.printf("the round of %.2f is %s\n",x,y);}else{int z = (int) Math.floor(x+0.5);System.out.printf("the round of %.2f is %s\n",x,z);}}}publicclass P221_6$10 {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input a double number!\n");double x = input.nextDouble();//////////////////////////rounded to tenths unitint y = (int) Math.floor(x*10);if (x*10 - y < 0.5) {System.out.printf("the round of %.2f is %s\n", x, (double)Math.floor(x*10)/10);} else {double z = Math.floor(x*10 + 0.5)/10;System.out.printf("the round of %.2f is %s\n", x, z);}}}publicclass P221_6$12 {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubRandom rand = new Random();System.out.printf("a) 1<= n <=2: %s\n", rand.nextInt(2)+1 ); System.out.printf("b) 1<= n <=100: %s\n", rand.nextInt(99)+1 ); System.out.printf("c) 0<= n <=9: %s\n", rand.nextInt(10)+1 ); System.out.printf("d) 1000<= n <=1112: %s\n", rand.nextInt(1113)+1 ); System.out.printf("e) -1<= n <=1 : %s\n", rand.nextInt(2)-1 ); System.out.printf("f) -3<= n <=11: %s\n", rand.nextInt(15)-3 );}}publicclass P222_6$13 {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubRandom rand = new Random();System.out.printf("a) 2 4 6 8 10 :%s\n", 2*(rand.nextInt(5)+1) );System.out.printf("b) 3 5 7 9 11: %s\n", 2*(rand.nextInt(5)+1) +1 );System.out.printf("c) 6 10 14 18 22: %s\n", 4*(rand.nextInt(5)+1) +2 );}}import java.util.*;publicclass P222_6$14 {publicvoid integerPower(int b, int ex){int ans = 1;for(int i = 1; i<= ex; i++){ans=ans*b ;}System.out.printf("the %s exponent of %s is : %s.\n", ex, b, ans);}publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input the base number: \n");int base = input.nextInt();System.out.print("input the exponent number: \n");int exponent = input.nextInt();P222_6$14 intpower = new P222_6$14();intpower.integerPower(base, exponent);}}publicclass P222_6$15 {publicstaticvoid main(String[] args) {System.out.print("Triangle\tSide1\tSide2\tSide3\n");System.out.print("1\t 3.0\t 4.0\t ");double Side11 = 3.0; double Side12 = 4.0;double Side13 = Math.sqrt(Math.pow(Side11,2)+Math.pow(Side12, 2)); System.out.printf("%s\n",Side13);//////////////System.out.print("1\t 5.0\t 12.0\t ");double Side21 = 5.0 ; double Side22 = 12.0;double Side23 = Math.sqrt(Math.pow(Side21,2)+Math.pow(Side22, 2)); System.out.printf("%s\n",Side23);//////////////System.out.print("1\t 8.0\t 15.0\t ");double Side31 = 8.0 ; double Side32 = 15.0;double Side33 = Math.sqrt(Math.pow(Side31,2)+Math.pow(Side32, 2)); System.out.printf("%s\n",Side33);}}publicclass P222_6$16 {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("Input two integer numbers >>>>>>\n");System.out.print("Input the first integer number:\n");int n1 = input.nextInt();System.out.print("Input the second integer number:\n");int n2 = input.nextInt();P222_6$16 comparison = new P222_6$16();comparison.multiple(n1, n2);}publicvoid multiple(int a, int b){int n = b % a;if (n == 0)System.out.printf("%s is %s-ple of %s.", b, b/a,a);//return b/a;elseSystem.out.printf("%s can not be divided by %s.",b, a);}}publicclass P222_6$17 {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("Input a integer numbers >>>>>>\n");System.out.print("Input integer number:\n");int n = input.nextInt();P222_6$17 comparison = new P222_6$17();comparison.isEven(n);}publicvoid isEven(int a){int n = a % 2;if (n == 0)System.out.printf("%s is a even number.",a);//return b/a;elseSystem.out.printf("%s is an odd number.",a);}}publicclass P222_6$18 {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("Input integer number to represent the lenth of a squre:\n");int side = input.nextInt();P222_6$18 sq= new P222_6$18();sq.squareOfAsterisks(side);}publicvoid squareOfAsterisks(int side){for(int i = 1; i<= side; i++){for(int j = 1; j <= side; j++){System.out.print("*");}System.out.print("\n");}}}publicclass P222_6$19 {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("Input integer number to represent the lenth of a squre:\n");int side = input.nextInt();P222_6$19 fc= new P222_6$19();fc.fillCharacter(side);}publicvoid fillCharacter(int side){for(int i = 1; i<= side; i++){for(int j = 1; j <= side; j++){System.out.print("#");}System.out.print("\n");}}}publicclass P223_6$20 {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("Input integer number to represent the ridius of a cirlce:\n");int r = input.nextInt();P223_6$20 cr =new P223_6$20();cr.circleArea(r);}publicvoid circleArea(int r){double ca = Math.PI * r * r;System.out.printf("The area of the circle is %s.", ca);}}publicclass P223_6$21 {/*** @param args*/publicstaticvoid main(String[] args) {Scanner input = new Scanner(System.in);System.out.print("Input two integer numbers >>>>>>\n");System.out.print("Input the first integer number:\n");int a = input.nextInt();System.out.print("Input the second integer number:\n");int b = input.nextInt();P223_6$21 comparison = new P223_6$21();comparison.displayDigits1(a, b);System.out.print("diaplay digits\n");comparison.displayDigits2(4562);}publicvoid displayDigits1(int a, int b) {// answers for a) and b)int n = a % b;int n1 = (a - n) / b;System.out.printf("%s/%s整数部分是%s, 余数是%s\n", a, b, n1, n);}publicvoid displayDigits2(int a){if ((a >= 0) && (a <= 9))System.out.printf("%s ", a);elseif ((a > 9) && (a <= 99))System.out.printf("%s %s", a / 10,a % 10);elseif ((a >=100) && (a <= 999))System.out.printf("%s %s %s", a / 100,(a - 100 * (a/100))/10,a % 10);elseif ((a >= 1000) && (a <= 9999))System.out.printf("%s %s %s %s", a / 1000,(a / 100) % 10, (a / 10) % 10, a % 10);elseif ((a >= 10000) && (a <= 99999))System.out.printf("%s %s %s %s %s", a / 10000,(a / 1000) % 10, (a / 100) % 10, a /10 % 10, a % 10);}}publicclass P223_6$22 {publicstaticvoid main(String[] args){Scanner input = new Scanner(System.in);System.out.print("input a number to represent your tempreture, '1' for Fahrenheit, '2' for Celsius:\n");int temtype = input.nextInt();System.out.print("\nInput the tempreture:\n");int temp = input.nextInt();P223_6$22 convert = new P223_6$22();if (temtype == 1)System.out.print(convert.convertFaToCel(temp)) ;elseSystem.out.print(convert.convertCelToFa(temp));}publicdouble convertFaToCel(int f) {double c = (double) 5 / 9 * (f - 32);return c;}publicdouble convertCelToFa(int c) {double f = (double) 9 / 5 * c + 32;return f;}}publicclass P223_6$23 {/*** @param args*/publicstaticvoid main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input 3 float number and the minimum:\n");double n1 = input.nextDouble();double n2 = input.nextDouble();double n3 = input.nextDouble();double n = Math.min(n1, Math.min(n2, n3));System.out.printf("\nThe minimum is %f\n\n", n);//Random randn = new Random();double n4 = randn.nextDouble(); System.out.printf("\nThe first random number is %f", n4);double n5 = randn.nextDouble(); System.out.printf("\nThe second random number is %f", n5);double n6 = randn.nextDouble(); System.out.printf("\nThe third random number is %f", n6);double nn = Math.min(n4, Math.min(n5, n6));System.out.printf("\nThe minimum is %f", nn);}}//import java.util.*;publicclass P223_6$24 {publicstaticvoid main(String[] args) {// Perfect number// Scanner input = new Scanner(System.in);int i, j, sum;for (i = 1; i<= 1000; i++) {sum = 0;for (j = 1; j <= i / 2; j++)if (i % j == 0)sum += j;if (sum == i)System.out.printf("\n%d是完数\n", i);}}}import java.util.*;publicclass P223_6$25 {publicstaticvoid main(String[] args) {// prime numberScanner input = new Scanner(System.in);System.out.print("input a integer number:\n");int n = input.nextInt();P223_6$25 checkp = new P223_6$25();// a)boolean p = checkp.checkPrimeNumber(n);if (p == false)System.out.printf("\n%s is not a prime number.", n);else {System.out.printf("\n%s is a prime number.", n);}// b)System.out.printf("\n\nThe prime numbers are: \n");for (int j = 1; j <= 10000; j++) {if (checkp.checkPrimeNumber(j) == true)System.out.printf("\n%s", j);}}publicboolean checkPrimeNumber(int a) {boolean flag = true;if (a <= 2) {flag = true;} else {for (int i = 2; i< a; i++) {if ((a % i) == 0) {flag = false;break;}// System.out.printf("\n%s is not a prime number.", a);}}return flag;}}import java.util.*;publicclass P224_6$26 {publicstaticvoid main(String[] args) {// TODO Auto-generated method stubSystem.out.print("input a integer number:\n");Scanner input = new Scanner(System.in);int n = input.nextInt();P224_6$26 test = new P224_6$26();int disp = test.reverse(n);System.out.printf("reverse number %s is : %s \n", n,disp);}publicint reverse(int n) {int m = 0;if ((n >= 0) && (n <= 9)) {m = n;} elseif ((n >= 10) && (n <= 99)) {m = n / 10 + n % 10 * 10;} elseif ((n >= 100) && (n <= 999)) {m = n / 100 + n / 10 % 10 * 10 + n % 10 * 100;} elseif ((n >= 1000) && (n <= 9999)) {m = n / 1000 + n / 100 % 10 * 10 + n / 10 % 10 * 100 + n % 10* 1000;} else {System.out.print("Input a small number");}return m;}}/*import java.util.Scanner;public class InvertedOrder {public static void main(String[] args) {Scanner number = new Scanner(System.in);intnum;System.out.println("必须输入一个正整数:");while (true) {num = number.nextInt();if (num<= 0) {System.out.println("必须输入一个正整数:");} else {System.out.println("您输入的数字是:" + num);String b = "";while (num != 0) {int nun = num % 10;b = b + nun;num = num / 10;}int c = Integer.parseInt(b);System.out.println("倒序以后为:" + c);System.out.println("是否还继续?否请按0;是请按任意数字键");Scanner src = new Scanner(System.in);intmun = src.nextInt();if (0 == mun) {System.out.println("您按啦数字:" + mun + ";程序已经结束任务。

Java实战经典(第六章课后题答案)

Java实战经典(第六章课后题答案)
super(name,age,sex); this.yearsalary=yearsalary; this.post=post; } public String Info() { return ()+",工资:"+this.yearsalary+",职位:"+this.post; } } class Staff extends Employee { private float monthsalary; private String post; public Staff(String name,int age,String sex,float monthsalary,String post) { super(name,age,sex); this.monthsalary=monthsalary; this.post=post; } public String Info() { return ()+",工资:"+this.monthsalary+",职位: "+this.post; } } public class Six04
public float getFoot(){ return this.foot ;
} public float getHeight(){
return this.height ; } } class Cycle extends Shape{ private float radius ; private static final float PI = 3.1415926f ; public Cycle(){} public Cycle(float radius){
4

Java语言程序设计基础篇课后题答案-Chapter 6 Arrays

Java语言程序设计基础篇课后题答案-Chapter 6 Arrays

Chapter 6 Arrays1. See the section "Declaring and Creating Arrays."2. You access an array using its index.3. No memory is allocated when an array is declared. The memory is allocated whencreating the array.x is 60The size of numbers is 304. Indicate true or false for the following statements:1. Every element in an array has the same type.Answer: True2. The array size is fixed after it is declared.Answer: False3. The array size is fixed after it is created.Answer: True4. The element in the array must be of primitive data type.Answer: False5. Which of the following statements are valid array declarations?int i = new int(30);Answer: Invaliddouble d[] = new double[30];Answer: Validchar[] r = new char(1..30);Answer: Invalidint i[] = (3, 4, 3, 2);Answer: Invalidfloat f[] = {2.3, 4.5, 5.6};Answer: Validchar[] c = new char();Answer: Invalid6. The array index type is int and its lowest index is 0.7. a[2]8. A runtime exception occurs.9. Line 3: the array declaration is wrong. It should be double[]. The array needs tobe created before its been used. e.g. new double[10]Line 5: The semicolon (;) at the end of the for loop heading should be removed.Line 5: r.length() should be r.length.Line 6: random should be random()Line 6: r(i) should be r[i].System.arraycopy(source, 0, t, 0, source.length);10.11. The second assignment statement myList = new int[20] creates a new array andassigns its reference to myList.12. False. When an array is passed to a method, the reference value of the array ispassed. No new array is created. Both argument and parameter point to the samearray.13.numbers is 0 and numbers[0] is 314.15. Only one variable-length parameter may be specified ina method and this parameter must be the last parameter. The method return type cannot be a variable-length parameter.16.The last oneprintMax(new int[]{1, 2, 3});is incorrect, because the array must of the double[] type.17. Omitted18. Omitted19. Omitted20 Simply change (currentMax < list[j]) on Line 10 to(currentMax > list[j])21 Simply change list[k] > currentElement on Line 9 tolist[k] < currentElement22. To apply java.util.Arrays.binarySearch(array, key), the array must be sorted inincreasing order.23.You can sort an array of any primitive types except boolean. The sort method is void,so it does not return a new array.24. Line 1: list is {2, 4, 7, 10}Line 2: list is {7, 7, 7, 7}Line 3: list is {7, 8, 8, 7}Line 4: list is {7, 8, 8, 7}25 int[][] m = new int[4][5];26 Yes. They are ragged array.27 array[0][1] is 2.28.int[][] r = new int[2];int[] x = new int[];int[][] y = new int[3][];Answer: Valid。

JAVA语言程序设计基础课后习题第六章

JAVA语言程序设计基础课后习题第六章

JAVA语⾔程序设计基础课后习题第六章//exercise 6.1package second;import java.util.Scanner;public class first {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner in=new Scanner(System.in);System.out.print("Enter the number of students:");int number=in.nextInt();System.out.print("Enter "+number+" scores:");int []score=new int[number];getscores(score);int best=max(score);for(int i=0;i<number;i++){System.out.println("Student "+i+" score is "+score[i]+" and grade is "+grade(score[i],best));}}public static void getscores(int []score){Scanner in=new Scanner(System.in);for(int i=0;i<score.length;i++){score[i]=in.nextInt();}}public static int max(int[] score){int max=score[0];for(int i=0;i<score.length;i++){if(max<score[i])max=score[i];}return max;}public static char grade(int score,int max){if(score>=max-10)return 'A';else if(score>=max-20)return 'B';else if(score>=max-30)return 'C';else if(score>=max-40)return 'D';elsereturn 'F';}}//exercise 6.2package second;import java.util.Scanner;public class second {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubint []number=get();reverseprint(number);}public static int[] get(){Scanner in=new Scanner(System.in);int[] number=new int[10];System.out.println("input 10 number:");for(int i=0;i<number.length;i++){number[i]=in.nextInt();}return number;}public static void reverseprint(int[]Array){for(int i=Array.length-1;i>=0;i--){System.out.print(Array[i]+" ");}}}//exercise 6.3package second;import java.util.Scanner;public class third {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner in=new Scanner(System.in);int[] newarray=new int[100];int temp;for(int i=0;i<newarray.length;i++){newarray[i]=0;}System.out.print("Enter the integers between 1 and 100:");while((temp=in.nextInt())!=0){newarray[temp]++;}resultprint(newarray);}public static void resultprint(int []array){for(int i=0;i<array.length;i++){if(array[i]==1)System.out.println(i+" occurs "+array[i]+" time");if(array[i]!=0&&array[i]!=1)System.out.println(i+" occurs "+array[i]+" times");}}}//exercise 6-4package first;import java.util.Scanner;public class first {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner in=new Scanner(System.in);int []score=new int[100];int i=0,sum=0,count=0;System.out.print("input integer:");while((score[i]=in.nextInt())!=-1){sum+=score[i++];count++;}int average=sum/count;int big=0,small=0;for(int j=0;j<count;j++){if(score[j]<average)small++;elsebig++;}System.out.println("average is "+average);System.out.println("better than average is "+big);System.out.println("small than average is "+small);}}//exercise 6-5package first;import java.util.Scanner;public class second {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stub Scanner in=new Scanner(System.in); System.out.print("Enter ten numbers:");int []integer=new int[10];int count=0;for(int i=0;i<10;i++){boolean judge=false;int temp=in.nextInt();for(int j=0;j<count;j++){if(temp==integer[j]){judge=true;}}if(!judge){integer[count++]=temp;}}System.out.print("input integer:");for(int i=0;i<count;i++){System.out.print(integer[i]+" ");}}}//exercise 6-7package first;public class third {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubint []counts=new int[10];for(int i=0;i<100;i++){int random=(int)(Math.random()*10); counts[random]++;}for(int i=0;i<10;i++){System.out.print(i+" ");}System.out.println();for(int i=0;i<10;i++){System.out.print(counts[i]+" ");}}}//exercise 6-8package first;public class fourth {/*** @param args*/public static int average(int[]array){int sum=0,count=0;for(int i=0;i<array.length;i++){sum+=array[i];count++;}return sum/count;}public static double average(double []array){double sum=0;int count=0;for(int i=0;i<array.length;i++){sum+=array[i];count++;}return sum/count;}}//exercise 6-9package first;public class fifth {/*** @param args*/public static double min(double []array){double min=array[0];for(int i=0;i<array.length;i++){if(min>array[i])min=array[i];}return min;}}//exercise 6-10package first;public class seventh {/*** @param args*/public static int indexOfSmallestElement(double[] array){ double min=array[0];for(int i=0;i<array.length;i++){if(min>array[i])min=array[i];}for(int i=0;i<array.length;i++){if(min==array[i])return i;}return 0;}}。

AnjoyoJava06课后习题-带答案

AnjoyoJava06课后习题-带答案

AnjoyoJava06课后习题-带答案一、选择题:1.下面关于异常的说法正确的一项是()。

A、异常就是在程序的运行过程中所发生的不正常的事件,但它不会中断正在运行的程序。

(没有UI的程序是一定会挂掉存在JFSW窗口不一定全部死掉)B、Error类和E某ception类都是Throwable类的子类。

C、E某ception处理的是Java运行环境中的内部错误或者硬件问题,比如,内存资源不足、系统崩溃等。

----ErrorD、Error处理的是因为程序设计的瑕疵而引起的问题或者外在的输入等引起的一般性问题,例如:在开平方的方法中输入了一个负数,对一个为空的对象进行操作以及网络不稳定引起的读取网络问题等。

------------E某ceptionA、错误的类型转换B、试图从文件结尾处读取信息--IOC、试图访问一个空对象D、数组越界访问3.引起IOE某ception异常的原因不包括下面哪一项()。

A、试图从文件结尾处读取信息A、ClaNotFoundE某ception:无法找到需要的类文件异常------OtherB、NumberFormatE某ception:数字转化格式异常---RTC、IllgalArgumentE某ception:非法参数值异常---RTD、IllegalStateE某ception:对象状态异常,如对未初始化的对象调用方法---RT5.IOE某ception异常不包括下面哪一项()。

A、EOFE某ception:读写文件尾异常B、InterruptedE某ception:线程中断C、SocketE某ception:Socket通信异常D、MalformedURLE某ception:URL格式错误异常6.下列关于try-catch-finally处理异常描述有误的一项是()。

A、异常处理可以定义在方法体、自由块或构造方法中。

B、catch()从句中引入一个可能出现的异常,一个try块只可以和一个catch()块配合以处理多个异常。

Java基础第6章编程题答案

Java基础第6章编程题答案

第六章集合编程题1.遍历一个LinkedList集合,写一个可以删除所有与“tom”相同的元素的静态方法。

(集合中的元素自行添加)注意:不要使用for循环遍历删除,会出现删除不干净的情况【参考答案】import java.util.ArrayList;import java.util.Iterator;import java.util.LinkedList;public class Test {public static void main(String[] args) {LinkedList<String> list=new LinkedList<String>();list.add("tom");list.add("jack");list.add("jone");list.add("tom");System.out.println(list);removes(list,"tom");System.out.println(list);}public static void removes(LinkedList<String> list, String s) {Iterator iterator = list.iterator();while (iterator.hasNext()) {String str = (String) iterator.next();if (str.equals(s)) {iterator.remove();}}}}2.如何判断两个集合是否有交集,并打印出他们的交集提示:判断这两个集合是否包含相同的对象或元素,可以使用retainAll方法:oldCourses.retainAll(newCoures)。

如果存在相同元素,oldCourses中仅保留相同的元素。

Java EE架构设计与开发教程方巍机工版课后习题答案第6章

Java EE架构设计与开发教程方巍机工版课后习题答案第6章

6.6 课后习题一、选择题1. 一般情况下,关系数据模型与对象模型之间有__________匹配关系。

(多选)A、表对应类B、记录对应对象C、表的字段对应类的属性D、表之间的参考关系对应类之间的依赖关系答案:ABC2. 事务隔离级别是由_______实现的?A、Java应用程序B、HibernateC、数据库系统D、JDBC驱动程序答案:C3、假设对Customer类的orders集合采用延迟检索策略,编译或运行以下程序,会出现的情况是_________。

Session session=sessionFactory.openSession();tx = session.beginTransaction();Customer customer=(Customer)session.get(Customer.class,new Long(1));mit();session.close();Iterator orderIterator=customer.getOrders().iterator();A、编译出错B、编译通过,并正常运行C、编译通过,但运行时抛出异常答案:C4、以下关于SessionFactory的说法_________正确?(多选)A、对于每个数据库事务,应该创建一个SessionFactory对象B、一个SessionFactory对象对应一个数据库存储源。

C、SessionFactory是重量级的对象,不应该随意创建。

如果系统中只有一个数据库存储源,只需要创建一个。

D、SessionFactory的load()方法用于加载持久化对象答案:BC5、<set>元素有一个cascade属性,如果希望Hibernate级联保存集合中的对象,casecade 属性应该取_________值?A、noneB、saveC、deleteD、save-update答案:D二、简答题1、简述对象关系映射ORM概念。

第6章课后答案

第6章课后答案

习题6一、选择题1.当单选按钮的Value属性为()时,表示该单选按钮被选中。

A.True B.Enable C.Checked D.Click2.当一个复选框被选中时,它的Value属性的值是()。

A.3 B.2 C.1 D.03.下列控件中没有Caption属性的是()。

A.框架B.列表框C.复选框D.单选按钮4.将数据项“China”添加到列表框List1中成为第2项应使用()语句。

A.List1.AddItem "China",1 B.List1.AddItem "China", 2C.List1.AddItem 1, "China" D.List1.AddItem 2, "China"5.引用列表框List1最后一个数据项,应使用()语句。

A.List1.List(List1.ListCount)B.List1.List(ListCount)C.List1.List(List1.ListCount-1)D.List1.List(ListCount-1)6.设组合框Combo1中有3个项目,则以下能删除最后一项的语句是()。

A.Combo1.RemoveItem Text B.Combo1.RemoveItem 3C.Combo1.RemoveItem 2 D.Combo1.RemoveItem Combo1.Listcount 7.清除列表框中所有列表项使用的方法是()。

A.Clear B.Cls C.Release D.Move8.滚动条控件的滑块在滚动条所处位置的值由滚动条的()属性表示。

A.Change B.LargeChange C.Value D.SmallChange 9.下列不能打开菜单编辑器的操作是________。

A.按Ctrl+E快捷键B.单击工具栏中的“菜单编辑器”按钮C.按Shift + Alt + M快捷键D.执行“工具”菜单中的“菜单编辑器”命令10.关于多重窗体的叙述中,正确的是________。

java chapter 6(带作业题)

java chapter 6(带作业题)
• private static float price; • private static int count; • 静态变量由类的所有实例共享;
• 程序第一次引用含有静态变量的类时,将静态变量 分配存储空间;
• 在方法中声明的局部变量不能具有静态属性。 • Java程序的main方法必须用static修饰符进行说明, 使解释器执行main方法时,不用实例化含main方 法的类。
8
• 6.4.2 同一个类的对象之间的依赖性 • 即一个类对象与本类的其他对象交互。要实现这一操作, 可以将一个类的对象作为一个参数传递给本类的一个方法, 使得该方法可以对作为参数得到的对象进行操作。 • 例如: str3 = str1.concat( str2) ;
例题 6.3 例题 6.4
9
• 6.4.3 聚合(has a )关系 • 一个聚合对象由其他的对象组成,形成一个”has a”关系 • 一个聚合对象的定义是:将其他对象的引用作为自己的实 例数据的对象。 • 聚合关系是依赖关系的特殊类型,即类A被类B定义为类B 的一部分时,类A便依赖类B,类B就是聚合类。 • 一个聚合类通常要调用其组成部分类的方法。 • 例题 6.5 • 例题 6.6 • 例题 6.7
14
• 6.5.1 Comparable接口 • 该接口定义在ng包中,该接口中只有一个方法 compareTo,该方法的参数是一个对象,返回值为整型值。 • Comparable接口的目的是提供对两个对象进行比较的通 用机制。 • 例如: • if (pareTo(obj2) < 0) • system.out.println (“obj1 is less than obj2”); • 6.5.2 Iterator接口 • 也定义在Java标准类库中,由代表一个对象结合的类使用, 主要提供了在一个对象集合中每操作一次移动到下一个对 象的方法。 • 该接口中的两个方法是hasNext和next方法。

java程序设计教程(第六版)课后习题答案

java程序设计教程(第六版)课后习题答案
public static void main(String[] args) {
int SECONDS=10853;
int Hour,Minute,Second;
Second=SECONDS%60;
Minute=(SECONDS-Second)%60;
Hour=(SECONDS-Second-Minute*60)/3600;
private double diameter;
public Sphere(){//构造方法:无参数
this.diameter = 1.0;
}
public Sphere(double d){ //构造方法:带一个参数
this.diameter = d;
}
public void setDiameter(double d) {//设置直径值的方法
page.drawOval (145, 65, 40, 40);// circle
page.setColor(Color.cyan);
page.drawString ("OLYMPIC LOGO", 40, 30);
}
}
2.19
import java.applet.*;
import java.awt.*;
this.diameter = d;
}
public double getDiameter(){//获取直径值的方法
return this.diameter;
System.out.println (SECONDS+"秒,转化为");
System.out.println (Hour+"时"+Minute+"分"+Second+"秒");

Java语言程序设计(一)课后习题第六章(附答案)

Java语言程序设计(一)课后习题第六章(附答案)
·getRealPart()获得复数对象的实部。
·getlmaginaryPart()获得复数对象的虚部。
·setRealPart(doubled)把当前复数对象的实部设置为给定的形参的数字。
·setlmaginaryPart(doubled)把当前复数对象的虚部设置为给定形参的数字。
·complexAdd(ComplexNumberc)当前复数对象与形参复数对象相加,所得的结果也是复数值,返回给此方法的调用者。
+ cNumber_2.toString() + “等于“
+ cNumber_plexMinus(cNumber_2).toString());
System.out.println(cNumber_1.toString() + “减“
+ d + “等于“
+ cNumber_plexMinus(d).toString());
System.out.println(cNumber_1.toString() + “乘“
+ cNumber_2.toString() + “等于“
+ cNumber_plexMulti(cNumber_2).toString());
System.out.println(cNumber_1.toString() + “乘“
{
public abstract string subMethod();
}
参考答案:
1. trueLeabharlann 2.A3.答:子类重新定义父类中已经存在的方法,称为方法的覆盖。注意:方法覆盖与域的隐藏不同。子类重新定义父类已有的域,并不能完全取代它从父类那里继承的同名的域,这个域仍然占用子类的内存空间,在某些情况下会被使用;而当子类重新定义父类的方法时,从父类那里继承来的方法将被新方法完全取代,不再在子类的内存空间中占一席之地。与方法的覆盖不同,重载不是子类对父类同名方法的重新定义,而是在一个类中定义了同名的不同方法。

VF课本第6章节答案.doc

VF课本第6章节答案.doc

・3. 5程序设计题1.“计算"按钮的Click事件代码如下:thisform.text3.value=thisform.textl.value*thisform.text2.value2.“平均数”按钮的Click事件代码如下:thisform.text3.value=(val(thisform.textl.value)+val(thisform.text2.value))/2 表单的DbICIick事件代码如下:thisform.release3.命令按钮“交换'啲“click"事件代码如F:Store thisform.textl.value to tthisform.textl.value=thisform.text2.valuethisform.text2.value=t4.c=val(thisform.textl.value)f=9/5*c+32thisfor m」abel3.caption=str(f,10,2)6. 3. 3用SQL语句完成下列操作1、(1) SELECT职工号,工资FROM仓库表,职工表;WHERE仓库表.仓库号二职工表.仓库号AND仓库衣.所在城市二”广州“(2) SELECT 仓库号,COUNTS), AVG(工资)FROM 职工表GROUP BY 仓库号HAVING C0UNT(*)>=2(3)CREATE VIEW ZG_view AS SELECT 职工号,姓名FROM 职工表2、S ELECT COUNT (DISTINCT 借书证号)FROM 借阅WHERE ;IN (SELECT 借书证号FROM 读者WHERE 单位=n CIE n)3、S ELECT S.学号,姓名,AVG(成绩)平均成绩FKOM S,SC WHERE S.学号二SC.学号;GROUP BY S.学号HAVING COUNT (*) >=5 ORDER BY 3 DESC4> (1) INSERT INTO STUDENT (学号,姓名,成绩,专业);VALUES (”2000538“,”王力“,587,”法律“)(2 ) UPDATE STUDENT SET 成绩二成绩+2() WHERE 专业二"法律”(3)ALTER TABLE STUDENT ADD 性别C(2)(4)ALTER TABLE STUDENT ALTER 姓名C(10)(5)SELECT 姓名,专业,MAX(成绩)FROM STUDENT GROUP BY 专业(6)SELECT 姓名,成绩FROM STUDENT WHERE 成绩〉=600 ORDER BY 成绩DESC(7)SELECT 专业,AVG(成绩)FROM STUDENT GROUP BY 专业(8)ALTER TABLE STUDENT DROP 性别5.( 1) SELECT * FROM STOCK WHERE 交易所=”深圳“(2)SELECT * FROM STOCK WHERE 单价>10(3)SELECT * FROM STOCK WHERE 股票名称LIKE M%电子%”(4)SELECT * FROM STOCK ORDER BY 单价(5)SELECT * FKOM STOCK WHERE 单价BETWEEN 10 AND 156.(1) SELECT SUM(现钞买入价*持有数量)AS人民币价值FROM持有者,兑换;WHERE兑换.外币代码=持有者.外币代码AND姓名=”刘剑“(2)UPDATE兑换SET基准价=基准价*1.05 WHERE外币名称=”美元” OR外币名称=“英镑”(3)DELETE FROM 持冇者WHERE外币代码IN;(SELECT外币代码FROM兑换WHERE外币名称二”欧元“)(4)SELECT姓名,COUNT(*)AS外币种类FROM 持有者;GROUP BY 姓名HAVING COUNT(*)>=3 ORDER BY 夕卜币种类,姓名DESC7、(1) ALTER TABLE 运动员ADD 得分N(2,0)(2)UPDATE运动员SET得分=2*投中2分球+3*投屮3分球+罚球(3)SELECT MAX(得分)得分FROM运动员WHERE投中3分球v=58、(1) SELECT |$名,出版社FROM图朽WHERE第一作者二”张三”(2)SELECT图书编号,借书U期FROM借阅WHERE还书日期IS NULL(3)SELECT* FROM 读者INTO CURSOR one(4)SELECT借书证号,姓名FROM读者WHERE单位LIKE ”%北京%”(5)SELECT图书编号,借书日期FROM借阅WHERE year•(借书日期)=2009(6)SELECT图书编号FROM借阅WHERE借书证号IN ;(SELECT借书证号FROM读者WHERE职称=“工程师”)9、SELECT * FROM order WHERE YEAR(签订FI 期)=2007 ORDER BY 金额DESC10、DELETE FROM order WHERE 签订Fl期<{A2002-l-l)11、(1) ALTER TABLE 歌手ADD 最后得分F(6,2)(2)INSERT INTO 评分(歌手号,分数,评委号)VALUES(“ 1001”,9.9,” 105”)(3)SELECT 歌手号,(SUM(分数)-MAX(分数)-MIN(分数))/ (COUNT(*)-2)最后得分;FROM 评分INTO DBF TEMP GROUP BY 歌手号ORDER BY 最后得分DESC(4)CREATE VIEW myview AS SELECT * FROM 歌手WHERE LEFT(歌手号7・3・4读程序,写结果1.13 212.343.2004.1 1 3 9 5 25 7 49165.756,M=10N=27.68.79.tHIS IS A cpu10.*****rp rj^ rjw11 .第1次显示:28.90元第2次显示:统计无效!12.37013.赵维季石雨14.010 女8915.016.71 6517.P( 1)=2 P(2)=4 P(3)=8b=1518.建国F 1 60年大庆19.数据库系统21. 100 200 40 20 200 40 20 3 422.64 29 87 69 20 29 42 5520.3 5 8 1323.12365424.环境艺术25.单击Commanding,显示学号为“1002”的记录;单击Command2时,显示所有3条记录。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

//test the 'Math' class//Math class is a part of ng package, so no need to import itpublic class p217_6$3 {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.printf( "Math.abs( 23.7 ) = %s\n", Math.abs( 23.7 ) );System.out.printf( "Math.abs( 23.7 ) = %f\n", Math.abs( 23.7 ) );System.out.printf( "Math.abs( 0.0 ) = %f\n", Math.abs( 0.0 ) );System.out.printf( "Math.abs( -23.7 ) = %f\n", Math.abs( -23.7 ) );System.out.printf( "Math.ceil( 9.2 ) = %f\n", Math.ceil( 9.2 ) );System.out.printf( "Math.ceil( -9.8 ) = %f\n", Math.ceil( -9.8 ) );System.out.printf( "Math.cos( 0.0 ) = %f\n", Math.cos( 0.0 ) );System.out.printf( "Math.exp( 1.0 ) = %f\n", Math.exp( 1.0 ) );System.out.printf( "Math.exp( 2.0 ) = %f\n", Math.exp( 2.0 ) );System.out.printf( "Math.floor( 9.2 ) = %f\n", Math.floor( 9.2 ) );System.out.printf( "Math.floor( -9.8 ) = %f\n",Math.floor( -9.8 ) );System.out.printf( "Math.log( Math.E ) = %f\n",Math.log( Math.E ) );System.out.printf( "Math.log( Math.E * Math.E ) = %f\n",Math.log( Math.E * Math.E ) );System.out.printf( "Math.max( 2.3, 12.7 ) = %f\n",Math.max( 2.3, 12.7 ) );System.out.printf( "Math.max( -2.3, -12.7 ) = %f\n",Math.max( -2.3, -12.7 ) );System.out.printf( "Math.min( 2.3, 12.7 ) = %f\n",Math.min( 2.3, 12.7 ) );System.out.printf( "Math.min( -2.3, -12.7 ) = %f\n",Math.min( -2.3, -12.7 ) );System.out.printf( "Math.pow( 2.0, 7.0 ) = %f\n",Math.pow( 2.0, 7.0 ) );System.out.printf( "Math.pow( 9.0, 0.5 ) = %f\n",Math.pow( 9.0, 0.5 ) );System.out.printf( "Math.sin( 0.0 ) = %f\n", Math.sin( 0.0 ) );System.out.printf( "Math.sqrt( 900.0 ) = %f\n",Math.sqrt( 900.0 ) );System.out.printf( "Math.tan( 0.0 ) = %f\n", Math.tan( 0.0 ) );}}import java.util.Scanner;public class p218_6$6a {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input the radius of a sphere:\n");double r = input.nextDouble();p218_6$6b compute = new p218_6$6b();//compute areadouble area = puteArea(r);System.out.printf("\nthe AREA of a sphere is: %f\n", area);//compute volumedouble volume = puteVolume(r);System.out.printf("\nthe VOLUME of a sphere is: %f\n", volume);}}public class p218_6$6b {public double computeArea(double r){double area = Math.PI * Math.pow(r, 2) ;return area;}public double computeVolume(double r){double volume = (4/3) * Math.PI * Math.pow(r, 3);return volume;}}public class p220_6$7 {public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.printf("x = Math.abs( 7.5 ), x=%s\n", Math.abs(7.5));System.out.printf("x = Math.floor( 7.5 ) , x=%s\n", Math.floor(7.5));System.out.printf("x = Math.abs( 0.0 ) , x=%s\n", Math.abs(0.0));System.out.printf("x = Math.ceil( 0.0 ) , x=%s\n", Math.ceil(0.0));System.out.printf("x = Math.abs( -6.4 ) , x=%s\n", Math.abs(-6.4));System.out.printf("x = Math.ceil( -6.4 ) , x=%s\n", Math.ceil(-6.4));System.out.printf("x = Math.ceil( -Math.abs( -8 + Math.floor( -5.5 ) ) ), x=%s\n",Math.ceil(-Math.abs(-8 + Math.floor(-5.5))));}}import java.util.*;public class p221_6$8 {public void caculateCharges(double in){if (in <= 3) {double totalcost=2;System.out.printf("the total cost is %.2f\n", totalcost);}else if (in > 3 && in <=24 ){double totalcost = 2 + (in - 3) * 0.5;if (totalcost > 10)totalcost =10;System.out.printf("the total cost is %.2f\n", totalcost);}else{System.out.print("an illegal input time");}}public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input the total parking time( <= 24 hour):\n");double inputn = input.nextDouble();//double totalcost = 0;p221_6$8 time = new p221_6$8();time.caculateCharges(inputn);}}public class P221_6$9 {public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input a double number!\n");double x = input.nextDouble();int y = (int) Math.floor(x);if (x-y<0.5){System.out.printf("the round of %.2f is %s\n",x,y);}else{int z = (int) Math.floor(x+0.5);System.out.printf("the round of %.2f is %s\n",x,z);}}}public class P221_6$10 {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input a double number!\n");double x = input.nextDouble();//////////////////////////rounded to tenths unitint y = (int) Math.floor(x*10);if (x*10 - y < 0.5) {System.out.printf("the round of %.2f is %s\n", x, (double)Math.floor(x*10)/10);} else {double z = Math.floor(x*10 + 0.5)/10;System.out.printf("the round of %.2f is %s\n", x, z);}}}public class P221_6$12 {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubRandom rand = new Random();System.out.printf("a) 1<= n <=2: %s\n", rand.nextInt(2)+1 );System.out.printf("b) 1<= n <=100: %s\n", rand.nextInt(99)+1 );System.out.printf("c) 0<= n <=9: %s\n", rand.nextInt(10)+1 );System.out.printf("d) 1000<= n <=1112: %s\n", rand.nextInt(1113)+1 ); System.out.printf("e) -1<= n <=1 : %s\n", rand.nextInt(2)-1 );System.out.printf("f) -3<= n <=11: %s\n", rand.nextInt(15)-3 );}}public class P222_6$13 {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubRandom rand = new Random();System.out.printf("a) 2 4 6 8 10 :%s\n", 2*(rand.nextInt(5)+1) );System.out.printf("b) 3 5 7 9 11: %s\n", 2*(rand.nextInt(5)+1) +1 );System.out.printf("c) 6 10 14 18 22: %s\n", 4*(rand.nextInt(5)+1) +2 );}}import java.util.*;public class P222_6$14 {public void integerPower(int b, int ex){int ans = 1;for(int i = 1; i <= ex; i++){ans=ans*b ;}System.out.printf("the %s exponent of %s is : %s.\n", ex, b, ans);}public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input the base number: \n");int base = input.nextInt();System.out.print("input the exponent number: \n");int exponent = input.nextInt();P222_6$14 intpower = new P222_6$14();intpower.integerPower(base, exponent);}}public class P222_6$15 {public static void main(String[] args) {System.out.print("Triangle\tSide1\tSide2\tSide3\n");System.out.print("1\t 3.0\t 4.0\t ");double Side11 = 3.0; double Side12 = 4.0;double Side13 = Math.sqrt(Math.pow(Side11,2)+Math.pow(Side12, 2)); System.out.printf("%s\n",Side13);//////////////System.out.print("1\t 5.0\t 12.0\t ");double Side21 = 5.0 ; double Side22 = 12.0;double Side23 = Math.sqrt(Math.pow(Side21,2)+Math.pow(Side22, 2)); System.out.printf("%s\n",Side23);//////////////System.out.print("1\t 8.0\t 15.0\t ");double Side31 = 8.0 ; double Side32 = 15.0;double Side33 = Math.sqrt(Math.pow(Side31,2)+Math.pow(Side32, 2)); System.out.printf("%s\n",Side33);}}public class P222_6$16 {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("Input two integer numbers >>>>>>\n");System.out.print("Input the first integer number:\n");int n1 = input.nextInt();System.out.print("Input the second integer number:\n");int n2 = input.nextInt();P222_6$16 comparison = new P222_6$16();comparison.multiple(n1, n2);}public void multiple(int a, int b){int n = b % a;if (n == 0)System.out.printf("%s is %s-ple of %s.", b, b/a,a);//return b/a;elseSystem.out.printf("%s can not be divided by %s.",b, a);}}public class P222_6$17 {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("Input a integer numbers >>>>>>\n");System.out.print("Input integer number:\n");int n = input.nextInt();P222_6$17 comparison = new P222_6$17();comparison.isEven(n);}public void isEven(int a){int n = a % 2;if (n == 0)System.out.printf("%s is a even number.",a);//return b/a;elseSystem.out.printf("%s is an odd number.",a);}}public class P222_6$18 {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("Input integer number to represent the lenth of a squre:\n");int side = input.nextInt();P222_6$18 sq= new P222_6$18();sq.squareOfAsterisks(side);}public void squareOfAsterisks(int side){f or(int i = 1; i <= side; i++){for(int j = 1; j <= side; j++){System.out.print("*");}System.out.print("\n");}}}public class P222_6$19 {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("Input integer number to represent the lenth of a squre:\n");int side = input.nextInt();P222_6$19 fc= new P222_6$19();fc.fillCharacter(side);}public void fillCharacter(int side){f or(int i = 1; i <= side; i++){for(int j = 1; j <= side; j++){System.out.print("#");}System.out.print("\n");}}}public class P223_6$20 {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("Input integer number to represent the ridius of a cirlce:\n");int r = input.nextInt();P223_6$20 cr =new P223_6$20();cr.circleArea(r);}public void circleArea(int r){double ca = Math.PI * r * r;System.out.printf("The area of the circle is %s.", ca);}}public class P223_6$21 {/*** @param args*/public static void main(String[] args) {Scanner input = new Scanner(System.in);System.out.print("Input two integer numbers >>>>>>\n");System.out.print("Input the first integer number:\n");int a = input.nextInt();System.out.print("Input the second integer number:\n");int b = input.nextInt();P223_6$21 comparison = new P223_6$21();comparison.displayDigits1(a, b);System.out.print("diaplay digits\n");comparison.displayDigits2(4562);}public void displayDigits1(int a, int b) {// answers for a) and b)int n = a % b;int n1 = (a - n) / b;System.out.printf("%s/%s整数部分是%s, 余数是%s\n", a, b, n1, n);}public void displayDigits2(int a){if ((a >= 0) && (a <= 9))System.out.printf("%s ", a);else if ((a > 9) && (a <= 99))System.out.printf("%s %s", a / 10,a % 10);else if ((a >=100) && (a <= 999))System.out.printf("%s %s %s", a / 100,(a - 100 * (a/100))/10,a % 10);else if ((a >= 1000) && (a <= 9999))System.out.printf("%s %s %s %s", a / 1000,(a / 100) % 10, (a / 10) % 10, a % 10);else if ((a >= 10000) && (a <= 99999))System.out.printf("%s %s %s %s %s", a / 10000,(a / 1000) % 10, (a / 100) % 10, a /10 % 10, a % 10);}}public class P223_6$22 {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("input a number to represent your tempreture, '1' for Fahrenheit, '2' for Celsius:\n");int temtype = input.nextInt();System.out.print("\nInput the tempreture:\n");int temp = input.nextInt();P223_6$22 convert = new P223_6$22();if (temtype == 1)System.out.print(convert.convertFaToCel(temp)) ;elseSystem.out.print(convert.convertCelToFa(temp));}public double convertFaToCel(int f) {double c = (double) 5 / 9 * (f - 32);return c;}public double convertCelToFa(int c) {double f = (double) 9 / 5 * c + 32;return f;}}public class P223_6$23 {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner input = new Scanner(System.in);System.out.print("input 3 float number and the minimum:\n");double n1 = input.nextDouble();double n2 = input.nextDouble();double n3 = input.nextDouble();double n = Math.min(n1, Math.min(n2, n3));System.out.printf("\nThe minimum is %f\n\n", n);//Random randn = new Random();double n4 = randn.nextDouble(); System.out.printf("\nThe first random number is %f", n4);double n5 = randn.nextDouble(); System.out.printf("\nThe second random number is %f", n5);double n6 = randn.nextDouble(); System.out.printf("\nThe third random number is %f", n6);double nn = Math.min(n4, Math.min(n5, n6));System.out.printf("\nThe minimum is %f", nn);}}public class P223_6$24 {public static void main(String[] args) {// Perfect number// Scanner input = new Scanner(System.in);int i, j, sum;for (i = 1; i <= 1000; i++) {sum = 0;for (j = 1; j <= i / 2; j++)if (i % j == 0)sum += j;if (sum == i)System.out.printf("\n%d是完数\n", i);}}}public class P223_6$25 {public static void main(String[] args) {// prime numberScanner input = new Scanner(System.in);System.out.print("input a integer number:\n");int n = input.nextInt();P223_6$25 checkp = new P223_6$25();// a)boolean p = checkp.checkPrimeNumber(n);if (p == false)System.out.printf("\n%s is not a prime number.", n);else {System.out.printf("\n%s is a prime number.", n);}// b)System.out.printf("\n\nThe prime numbers are: \n");for (int j = 1; j <= 10000; j++) {if (checkp.checkPrimeNumber(j) == true)System.out.printf("\n%s", j);}}public boolean checkPrimeNumber(int a) {boolean flag = true;if (a <= 2) {flag = true;} else {for (int i = 2; i < a; i++) {if ((a % i) == 0) {flag = false;break;}// System.out.printf("\n%s is not a prime number.", a);}}return flag;}}import java.util.*;public class P224_6$26 {public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.print("input a integer number:\n");Scanner input = new Scanner(System.in);int n = input.nextInt();P224_6$26 test = new P224_6$26();int disp = test.reverse(n);System.out.printf("reverse number %s is : %s \n", n,disp);}public int reverse(int n) {int m = 0;if ((n >= 0) && (n <= 9)) {m = n;} else if ((n >= 10) && (n <= 99)) {m = n / 10 + n % 10 * 10;} else if ((n >= 100) && (n <= 999)) {m = n / 100 + n / 10 % 10 * 10 + n % 10 * 100;} else if ((n >= 1000) && (n <= 9999)) {m = n / 1000 + n / 100 % 10 * 10 + n / 10 % 10 * 100 + n % 10* 1000;} else {System.out.print("Input a small number");}return m;}}/*import java.util.Scanner;public class InvertedOrder {public static void main(String[] args) {Scanner number = new Scanner(System.in);int num;System.out.println("必须输入一个正整数:");while (true) {num = number.nextInt();if (num <= 0) {System.out.println("必须输入一个正整数:");} else {System.out.println("您输入的数字是:" + num);String b = "";while (num != 0) {int nun = num % 10;b = b + nun;num = num / 10;}int c = Integer.parseInt(b);System.out.println("倒序以后为:" + c);System.out.println("是否还继续?否请按0;是请按任意数字键");Scanner src = new Scanner(System.in);int mun = src.nextInt();if (0 == mun) {System.out.println("您按啦数字:" + mun + ";程序已经结束任务。

相关文档
最新文档