当前位置:文档之家› Java基础教程(第3版)习题答案

Java基础教程(第3版)习题答案

Java基础教程(第3版)习题答案
Java基础教程(第3版)习题答案

部分习题答案

第一章

【答案】答案见教材<略>。

第二章

1. 请说明注释的作用。

【答案】答案见教材<略>。

2. 判断下列那些是标识符?

(1) 3class

(2) byte

(3) ? room

(4) Beijing

(5) beijing

【答案】(1)(2)(3)不是标识符,因为标识符不能已数字开始,也不能是保留关键字(如byte),不能以?开始。

3. 请指出下列声明字符变量ch的语句是否存在错误?如果有,请改正。

(1)char ch = 'A';

(2)char ch = '\u0020';

(3)char ch = 88;

(4)char ch = 'ab';

(5)char ch = "A";

【答案】(4)错,因为关键字char是用于声明字符变量,不可声明字符串变量。

4. 如果int x=1,y=-2,n=10;那么,表达式x+y+(--n)*(x>y&&x>0?(x+1):y)的值是什么类型?结果是多少?

【答案】int型,值为17。

5. 如果int k=1,那么'H'+k的类型是什么?下面语句是否存在差错?如果有,请改正。

(1)int k=1;

(2)char ch1,ch2;

(3)ch1='H'+k;

(4)ch2=98;

【答案】'H'+k的类型为int型。

(3)有错。'H'+k为int型,ch1为char型,将高精度赋给低精度类型时必须实行强制转换。

6. 请指出下面程序在编译时是否会出现错误。如果有,请改正。

public class doubleTointExample {

public static void main(String args[ ]) {

int a;

double b=1,c=2;

a=(int)(b+c);

System.out.println("a="+a);

}

}

【答案】无错误。输出结果:a=3

7. 请指出执行完下面程序后x、y和z的输出值是多少?请上机验证。

public class doubleTointExample {

public static void main(String args[ ]) {

int x,y,z;

x=1;

y=2;

z=(x+y>3?x++:++y);

System.out.println("x="+x);

System.out.println("y="+y);

System.out.println("z="+z);

}

}

【答案】

x=1

y=3

z=3

8. 请指出下面程序片段输出的结果是什么。

int i=1,j=10;

do

{

if (i++>--j) break;

}while(i<5);

System.out.println(“i=”+i+”<--->”+“j=”+j);

【答案】i=5<--->j=6

9. 请分别用if-else语句和switch语句编写实现下列功能的程序。

某同学某门课的成绩可能的结果为1,2,3,4,5。当成绩为1时请输出不及格;成绩为2时请输出及格;成绩为3时请输出中等;成绩为4时请输出良好;成绩为5时请输出优秀。

【答案】

/*if-else描述程序*/

public class xt020901 {

public static void main(String args[ ]) {

int score=4;

if (score==1)

{System.out.println("不及格");}

else if (score==2)

{System.out.println("及格");}

else if (score==3)

{System.out.println("中等");}

else if (score==4)

{System.out.println("良好");}

else {System.out.println("优秀");}

}

}

/*switch描述程序*/

public class xt020902 {

public static void main(String args[ ]) {

int score=4;

switch (score)

{

case 1 :

System.out.println("不及格");

break;

case 2 :

System.out.println("及格");

break;

case 3 :

System.out.println("中等");

break;

case 4 :

System.out.println("良好");

break;

case 5 :

System.out.println("优秀");

break;

}

}

}

10. 请编写输出乘法口诀表的程序。

乘法口诀表的部分内容如下:

1*1=1

1*2=2 2*2=3

1*3=3 2*3=6 3*3=9

1*4=4 2*4=8 3*4=12 4*4=16

……

public class xt0210

{

public static void main(String args[ ])

{final double PI = 3.141592654;

double area,r;

area =PI*r*r;

System.out.println(“面积=”+area);

}

}

【答案】

public class xt0210{

public static void main(String args[ ]) {

int i,j;

for(i=1;i<=9;i++)

{

for(j=1;j<=i;j++)

System.out.print(j+"*"+i+"="+i*j+" ");

System.out.println();

}

}

}

11. 请编写程序实现如下效果图。

【答案】

public class xt0211{

public static void main(String args[ ]) {

int i,j,k,num;

char ch;

num='A'-1;

for(i=1;i<=4;i++)

{

for(k=1;k<=4-i;k++)

System.out.print(" ");

for(j=1;j<=i;j++)

{

num=num+1;

ch=(char)num;

System.out.print(ch+" ");

}

System.out.println();

}

for(i=1;i<=4;i++)

{

for(k=1;k<=i-1;k++)

System.out.print(" ");

for(j=1;j<=5-i;j++)

{

num=num+1;

ch=(char)num;

System.out.print(ch+" ");

}

System.out.println();

}

}

}

12. 分别利用for语句、while语句以及do while语句编写一个求和程序(即sum=1+2+3+…+n)。【答案】

/*for语句实现*/

public class xt021201{

public static void main(String args[ ]) {

int i,n=100;

long sum=0;

for(i=1;i<=n;i++)

sum=sum+i;

System.out.println("sum[1:n]="+sum);

}

}

/*while语句实现*/

public class xt021202{

public static void main(String args[ ]) {

int i,n=100;

long sum=0;

i=1;

while(i<=n)

{

sum=sum+i;

i=i+1;

}

System.out.println("sum[1:n]="+sum);

}

}

/*do while语句实现*/

public class xt021203{

public static void main(String args[ ]) {

int i,n=100;

long sum=0;

i=1;

do

{

sum=sum+i;

i=i+1;

}

while (i<=n);

System.out.println("sum[1:n]="+sum);

}

}

13.编写一个利用简单迭代法求解下列方程的Java程序。

32

-+-=

x x x

24360

参考答案:

//程序名称:xt0213.java

//功能:方程求解的应用

//2*x*x*x-4*x*x+3*x-6=0

import java.io.* ; //引入类库

public class xt0213{ //定义类

public static void main(String args[]) { //定义main方法

double x0=0.1,x,eps=0.000001;

x=(-2*x0*x0*x0+4*x0*x0+6)/3;

while((x-x0)>eps)

{

x0=x;

x=(-2*x0*x0*x0+4*x0*x0+6)/3;

}

System.out.println("方程的跟="+x);

}

}

14、题目:判断3-1000之间有多少个素数,并输出所有素数。

程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。

public class xt0213 {

public static void main(String[] args) {

int count = 0;

for(int i=3; i<=1000; i+=2) {

boolean b = false;

for(int j=2; j<=Math.sqrt(i); j++)

{

if(i % j == 0) { b = false; break; }

else { b = true; }

}

if(b == true) {count ++;System.out.println(i );}

}

System.out.println( "素数个数是: " + count);

}

}

15、输入某年某月某日,判断这一天是这一年的第几天?

【参考答案】

import java.util.*;

public class xt0214 {

public static void main(String[] args) {

int year, month, day;

int days = 0;

int d = 0;

int e;

InputData data0 = new InputData();

do {

e = 0;

System.out.print("输入年:");

year =data0.inputInt();

System.out.print("输入月:");

month = data0.inputInt();

System.out.print("输入天:");

day = data0.inputInt();

if (year < 0 || month < 0 || month > 12 || day < 0 || day > 31) {

System.out.println("输入错误,请重新输入!");

e=1 ;

}

}while( e==1);

for (int i=1; i

switch (i) {

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

days = 31;

break;

case 4:

case 6:

case 9:

case 11:

days = 30;

break;

case 2:

days=28;

if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {

days = 29;

}

break;

}

d=d+days;

}

System.out.println(year + "-" + month + "-" + day + "是这年的第" + (d+day) + "天。");

}

}

class InputData{

public int inputInt() {

int value = 0;

Scanner s = new Scanner(System.in);

value = s.nextInt();

return value;

}

}

12. 复习break和continue语句,调试本章设计这两个语句的程序。

【答案】答案见教材<略>。

第三章

1. 选择题

(1) 不允许作为类及类成员的访问控制符的是( )。

A. public

B. private

C. static

D. protected

【答案】C

(2) 为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( )。

A. static void method( )

B. public void method( )

C. final void method( )

D. abstract void method( )

【答案】A

(3) Java中main()函数的值是( )。

A. String

B. int

C. char

D. void

【答案】D

2. 改错题

(1) 一个名为Hello.java程序如下:

//Hello.java程序

public class A

{

void f()

{ System.out.println("I am A"); }

}

class B

{ }

public class Hello

{

public static void main (String args[ ])

{

System.out.println("你好,很高兴学习Java");

A a=new A();

a.f();

}

}

要求:指出错误,说明错误原因,并改正。

【答案】

错误原因:一个程序中不可同时申明一个以上的public类。

改正措施:将public class A变为class A即可

(2) 类A的定义如下:

class A{

void f() {

int u=(int)(Math.random()*100);

int v,p;

if (u>50) {v=9;}

p=v+u;

}

要求:指出错误,说明错误原因,并改正。

【答案】

错误原因:Java语言规定,任何变量在使用之前,必须对变量赋值。由于u的值是由随机方法产生的,当u<=50时,v在使用前没有赋值,此时执行p=v+u;会出现错误。

改正措施:将int v,p;变为int v=0,p;即可

(3) B.java内容如下:

class A{

int x,y;

static float f(int a)

{return a;}

float g(int x1,int x2)

{return x1*x2;}

}

public class B{

public static void main(String args[]) {

A a=new A();

A.f(3);

a.f(4);

a.g(2,5);

A.g(3,2);

}

}

要求:指出错误,说明错误原因,并改正。

【答案】

错误原因: A.g(3,2);由于类方法不仅可以由对象调用而且还可以直接由类名调用,而实例方法不能由类名调用。

改正措施:删除A.g(3,2);或将A.g(3,2);改为 a.g(3,2);

3. 简答题

(1) 简述面向对象程序和面向过程程序设计的异同。

(2) 简述类中成员变量的分类及差异。

(3) 简述类中方法的分类及差异。

(4) 简述类中变量的初始化方式。

(5) 简述类中成员的几种访问控制修饰符的差异,并举例说明。

(6) 简述构造方法的作用。

【答案】答案见教材<略>。

4.编程题

(1)定义一个长方形类myBox并在另一类中使用,其中myBox类包含长length和宽width 两个成员变量,和计算面积、周长、修改长length和宽width等方法。

public class Test1{

public static void main(String args[ ]){

myBox obj=new myBox();

int x=10,y=20;

obj.setvalue(x,y);

System.out.println("width="+obj.width+" length="+obj.length);

System.out.println("周长="+obj.circle());

System.out.println("面积="+obj.area());

}

}

class myBox{

int width,length;

void setvalue(int width,int length)

{

this.width=width;

this.length=length;

}

int circle()

{

return 2*(width+length);

}

int area()

{

return width*length;

}

}

(2)利用递归输入如下图形。

###################

###############

###########

#######

###

程序如下所示。

//程序名称:Je030515.java

//功能:利用递归输出特定图形

class RecursionApp2{

void output(char ch,int k ) {

if(k>0) {

System.out.print(ch);

output(ch,k – 1);

}

}

void show(char ch,int m,int n ) {

if(n>0) {

output(' ',m);

output(ch,n);

System.out.println( );

show(ch,m+2,n – 4);

}

}

}

public class Je030515{

public static void main(String args[ ]){

RecursionApp2 obj=new RecursionApp2( );

obj.show('#',4,19);

}

}

(3)定义满足以下要求的复数类Complex:

1) 复数类Complex 的属性有:

realPart : int型,代表复数的实数部分

imagePart : int型,代表复数的虚数部分

2) 复数类Complex 的方法有:

Complex( ) : 构造函数,将复数的实部和虚部都置0

Complex( int r , int i ) : 构造函数,形参r 为实部的初值,i为虚部的初值。addComplex(Complex a) : 计算当前复数对象与形参复数对象相加。

编写一个完整的Java Application程序使用复数类Complex验证两个复数1+2i 和3+4i 相加产生一个新的复数4+6i 。

参考答案:

Complex{

int RealPart;

int ImagePart;

Complex(){

RealPart=0;

ImagePart=0;

}

Complex(int x,int y){

RealPart=x;

ImagePart=y;

}

addComplex(Complex c1){

RealPart= RealPart+c1.RealPart;

ImagePart= ImagePart+ c1.ImagePart;

}

}

public class xt020902 {

public static void main(String args[ ]) {

Complex c1=new Complex(1,2);

Complex c2=new Complex(1,2);

System.out.print(“复数c1的实部=”+c1.RealPart+”虚部=” +c1.ImagelPart)

System.out.print(“复数c2的实部=”+c1.RealPart+”虚部=” +c1.ImagelPart)

c1.addComplex(c2);

System.out.print(“复数c1=c1+c2的实部=”+c1.RealPart+”虚部=” +c1.ImagelPart) }

}

(3)定义一个二维向量类,其中a、b为其属性,主要操作为:

向量相加:=

向量相减:=

向量内积:×=a×c+b×d

编程定义该类,并使用该类。

参考答案:

//程序名称:Java030801.java

//目的:演示自定义类及其如何使用

class MyVector{

float x,y; //表示向量中的x,y

myVector(float x,float y){

this.x=x;this.y=y;

}

void setVector(float x,float y){

this.x=x;this.y=y;

}

//向量相加+=

void addVector(myVector v1,myVector v2){

this.x=v1.x+v2.x;

this.y=v1.y+v2.y;

}

//向量相减-=

void minusVector(myVector v1,myVector v2){

this.x=v1.x-v2.x;

this.y=v1.y-v2.y;

}

//向量内积·=a×c+b×d

float multVector(myVector v1){

return this.x*v1.x+this.y*v1.y;

}

//显示向量

void showVector(){

System.out.println("="+"<"+x+","+y+">");

}

}

public class Java030801{

public static void main(String args[ ]) {

MyVector a1=new MyVector(1,2);

MyVector a2=new MyVector(3,4);

MyVector a3=new MyVector(0,0);

a1.showVector();

a2.showVector();

a3.addVector(a1,a2);

a3.showVector();

a3.minusVector(a1,a2);

a3.showVector();

}

}

第四章

1. 简述Java中继承的含义及特点。

【答案】答案见教材<略>。

2. 指出下列程序中的错误,请说明错误原因。

class A {

public int a = 1;

private int b = 2;

protected int c = 3;

int d=4;

public int dispA() { return a; }

private int dispB() { return b; }

protected int dispC() { return c; }

int dispD() { return d; }

}

public class B extends A {

public static void main (String args[ ]) {

B bb=new B();

bb.testVisitControl ();

}

public void testVisitControl () {

System.out.println(a+dispA());

System.out.println(b+dispB());

System.out.println(c+dispC());

System.out.println(d+dispD());

}

}

【答案】System.out.println(b+dispB()); 行编辑时出现错误。原因如下:

(1) 子类B和父类A在同一包中;

(2) 子类B不能继承父类的private型属性和方法。

3. 根据下面程序片段,画出类和对象的内存映像图。

class A{

static int sv1=10;

int sv2=20;

int sv3=30;

static void sf1(){…}

void f1(){…}

}

class B extends A{

static int sv2=30;

int v2=3;

void f1(){…}

}

A ref1=new A();

B ref2=new B();

ref1=ref2;

【答案】

4. 简述子类对象的成员初始化的方法。

【答案】答案见教材<略>。

5. 简述成员变量的隐藏的含义,并举例说明。

【答案】答案见教材<略>。

6. 简述方法的重载和方法的覆盖的区别,并举例说明。【答案】答案见教材<略>。

7. 列举this和super的用途。

【答案】答案见教材<略>。

8. 指出下列程序运行的输出结果。

class Point {

int x, y;

Point( ){ this(-1,-1); }

Point(int a, int b){ x=a; y=b; }

void showxy(){

System.out.println(“x=”+x+” y=”+y);

}

}

public class reloadingExample {

public static void main (String args[ ]) {

Point a=new Point ();

Point b=new Point (1,1);

a.showxy();

b.showxy();

}

}

【答案】输出结果为:

x=-1 y=-1

x=1 y=1

9. 指出下列程序运行的输出结果。

class A{

int x=1, y=2;

double add(){ return x+y; }

}

class B extends A{

int x=10,y=20;

double add(){ return super.x+super.y ; }

}

class ex2 {

public static void main(String args[ ]){

A a=new A();

B b=new B();

System.out.println("a.add="+a.add());

System.out.println("b.add="+b.add());

}

}

【答案】输出结果为:

a.add=3.0

b.add=3.0

10. 简述接口和抽象类的含义,以及它们两者之间的不同。

【答案】答案见教材<略>。

第五章

1. 为什么说Java多维数组是数组元素为数组的一维数组,请用事实说明。

【答案】答案见教材<略>。

2. 判断下面数组的定义是否正确?如果不正确,请改正。

(1) int a[5];

char ch[5][4];

(2) int a[ ][ ]=new int[ ][4];

(3) int N=10;

int a=new int[N];

【答案】

(1)数组定义错。因为数组声明时方括号中不能用数字,即不允许静态说明数组。

(2) 数组定义错。因为数组维数声明顺序应该从高到低,先声明高维,再声明低维。

(3)正确。因为数组元素个数可以是常量,也可以是变量。

3. 若int[][] a={{1,2},{3,4,5},{6,7,8},{9,10},{11,12,13,14,15}},请问 a.length,a[2].length,

a[3].length分别等于多少?

【答案】a.length,a[2].length, a[3].length分别等于5、3、2。

4. 写出下列程序的运行结果。

class A{

void operate(int c[]){

int i;

for(i=0;i

}

}

public class ArrayExample4{

public static void main(String [ ] args){

A a=new A();

int b[ ]={1,2,3,4};

a. operate (b);

for(int i=0;i< b.length;i++) System.out.println(b[i]);

}

}

【答案】运行结果为:

3

6

9

12

5. 写出下列程序的运行结果。

public class StringExample4{

public static void main(String [ ] args){

String s1="abc";

String s2=s1;

s2+="def";

s1.concat("def");

System.out.println("s1="+s1+"s2="+s2);

}

}

【答案】运行结果为:

s1=abc s2=abcdef

6. 写出下列程序运行的结果。

public class StringExample5{

public static void main(String [ ] args){

String s[]={"ab","c","d"};

reverse(s[0],s[1]);

System.out.println("s[0]="+s[0]+" s[1]="+s[1]);

}

static void reverse(String s0, String s1){

String s;

s=s0;

s0=s1;

s1=s;

}

}

【答案】运行结果为:

s[0]=ab s[1]=c

7. 写出下列程序的运行结果。

public class StringExample6{

public static void main(String [ ] args){

String s[]={"ab","c","d"};

reverse(s);

System.out.println("s[0]="+s[0]+" s[1]="+s[1]);

}

static void reverse(String s[]){

String s0;

s0=s[1];

s[1]=s[0];

s[0]=s0;

}

}

【答案】运行结果为:

s[0]=c s[1]=ab

8. 写出下列程序的运行结果。

public class StringBufferExample3 {

public static void main (String [] args) {

StringBuffer s1= new StringBuffer ("AB");

StringBuffer s2 = new StringBuffer ("CD");

operate (s1,s2);

System.out.println("s1="+s1+" s2="+s2);

}

static void operate(StringBuffer x, StringBuffer y){

x.append(y);

x= y;

}

}

【答案】运行结果为:

s1=ABCD s2=CD

9.判断一个数是否是回文数。如,12321是回文数,个位与万位相同,十位与千位相同。【参考答案】

import java.util.*;

public class xt0509 {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

boolean is =true;

System.out.print("请输入一个正整数:");

long a = s.nextLong();

String ss = Long.toString(a);

char[] ch = ss.toCharArray();

int j=ch.length;

for(int i=0; i

if(ch[i]!=ch[j-i-1]){is=false;}

}

if(is==true){System.out.println("这是一个回文数");}

else {System.out.println("这不是一个回文数");}

}

}

10.输入20个数,并对20个数进行排序。

import java.util.*;

public class xt0510 {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

int[] a = new int[20];

System.out.println("请输入20个整数:");

for(int i=0; i<20; i++) {

a[i] = s.nextInt();

}

for(int i=0; i<10; i++) {

for(int j=i+1; j<10; j++) {

if(a[i] > a[j]) {

int t = a[i];

a[i] = a[j];

a[j] = t;

}

}

}

for(int i=0; i<10; i++) {

System.out.print(a[i] + " ");

}

}

}

11.打印出杨辉三角形。

1

Java程序设计实例教程考试题

Java程序设计练习题 一、选择题 1、为使Java程序独立于平台,Java虚拟机把字节码与各个操作系统及硬件( A ) A)分开B)结合 C)联系D)融合 2、Java语言与C++语言相比,最突出的特点是( C ) A)面向对象B)高性能 C)跨平台D)有类库 3、下列Java源程序结构中前三种语句的次序,正确的是(D) A)import,package,public class B)import必为首,其他不限 C)public class,package,import D),import,public class 4、在JDK目录中,Java程序运行环境的根目录是( A ) A)bin B)demo C)lib D)jre 5、下列运算符中属于关系运算符的是(A ) A)== B).= C)+= D)-= 6、下列布尔变量定义中,正确并且规范的是( B ) A)BOOLEAN canceled=false; B)boolean canceled=false; C)boolean CANCELED=false; D)boolean canceled=FALSE; 7、下列关键字中可以表示常量的是( A ) A)final B)default C)private D)transient 8、下列运算符中,优先级最高的是( A ) A)++ B)+ C)* D)> 9、Java中的基本数据类型int在不同的操作系统平台的字长是( B ) A)不同的B)32位 C)64位D)16位

10、给一个short类型变量赋值的范围是( C ) A)-128 至 +127 B)-2147483648至 +2147483647 C)-32768至 +32767 D)-1000至 +1000 11、下列运算中属于跳转语句的是( D ) A)try B)catch C)finally D)break 12、switch语句中表达式(expression)的值不允许用的类型是( C ) A)byte B)int C)boolean D)char 13、下列语句中,可以作为无限循环语句的是( A ) A)for(;;) {} B)for(int i=0; i<10000;i++) {} C)while(false) {} D)do {} while(false) 14、下列语句中执行跳转功能的语句是( C ) A)for语句B)while语句 C)continue语句D)switch语句 15、下列表达式中,类型可以作为int型的是( C ) A)“abc”+”efg”B)“abc”+’efg’ C)‘a’+’b’D)3+”4” 17、数组中各个元素的数据类型是( A ) A)相同的B)不同的 C)部分相同的D)任意的 18、在Java语言中,被成为内存分配的运算符是( A ) A)new B)instance of C)[] D)() 19、接口中,除了抽象方法之外,还可以含有( B ) A)变量B)常量 C)成员方法D)构造方法 20、下列能表示字符串s1长度的是( A ) A)s1.length()B)s1.length C)s1.size D)s1.size() 21、StringBuffer类字符串对象的长度是( C ) A)固定B)必须小于16个字符 C)可变D)必须大于16个字符 22、构造方法名必须与______相同,它没有返回值,用户不能直接调用它,只能通过new调用。( A ) A)类名B)对象名 C)包名D)变量名 23、子类继承了父类的方法和状态,在子类中可以进行的操作是( D ) A)更换父类方法B)减少父类方法 C)减少父类变量D)添加方法 24、String、StingBuffer都是______类,都不能被继承。( C )

java基础测试题及答案

一、选择题(每题2分,共40分) 1、下面哪个是Java语言中正确的标识符( C ) A、3com B、import C、that D、this 2、下面哪个语句(初始化数组)是不正确的:(B) A.int x[] = {1,2,3}; B.int x[3] = {1,2,3}; C.int[] x = {1,2,3}; D.int x[] = new int[]{1,2,3}; 3、下述概念中不属于面向对象方法的是( D )。 A.对象、消息 B.继承、多态 C.类、封装 D.过程调用 4、下面的代码段中,执行之后i 和j 的值是什么? ( B ) int i = 1; int j; j = i++*2+3*--i; A.1, 2 B.1, 5 C.2, 1 D.2, 2 5、下面哪条语句把方法声明为抽象的公共方法?(B ) A.public abstract method(); B.public abstract void method(); C.public abstract void method(){} D.public void method() extends abstract; 6、下面关于java中类的说法哪个是不正确的?( C ) A.类体中只能有变量定义和成员方法的定义,不能有其他语句。 B.构造函数是类中的特殊方法。 C.类一定要声明为public的,才可以执行。 D.一个java文件中可以有多个class定义。 7、假设A类有如下定义,设a是A类的一个实例,下列语句调用哪个是错误的?( C ) class A { int i; static String s; void method1() { } static void method2() { } } A、System.out.println(a.i); B、a.method1(); C、A.method1(); D、A.method2() 8、容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小 的变化而改变? ( B ) A、CardLayout B、FlowLayout C、BorderLayout D、GridLayout 9、下列哪个用户图形界面组件在软件安装程序中是常见的? ( C ) A.滑块 B.进度条 C.按钮 D.标签

新视野大学英语读写教程2(第三版)第二单元练习答案

Unit 2 Section A 3 1 promotes 2 accelerate 3 mystery 4 insight 5 boost 6 analysis 7 calculate 8 barriers 9 destruction 10 prospect 4–ing promising bearing housing -ive objective offend exclude excess execute -ify intensify identify 5 1 excess 2 bearing 3 objective 4 intensify 5 execute 6 promising 7 exclude 8 identity 9offend 10 housing 6 1 C 2 H 3 D 4 J 5 B 6 L 7 M 8 G 9 F 10 A 7 1 are liable to 2 in favor of 3 is bound to 4 speculate about 5 invested…with 6 stand up for 7 in the form of 8 prepared for 9 in the company of 10 in succession 9慕课是一种网络课程,它旨在通过网络实现广泛参与和开放接入。慕课是远程教育迈出的最新一步,现已在高等教育领域迅速引领潮流。通过这些课程,大学可以扩大影响的范围,从影响成千上万住在城里付学费的学生,扩展到惠及全球上百万的学生。除了拥有传统的课程资源,慕课还给使用者特供互动论坛,支持学生和讲师之间的交流。慕课能够促进参与者之间的交流,使得多种观点、知识和技能涌现到课堂上来;它鼓励人们尝试之前不可能尝试的课程,甚至是尝试新的教育方式;它提供多种学习课程资料的方式,鼓励多模式学习,以各种学习风格满足学习者的需求;另外,慕课促进教学的改善,使技术在面对面授课中得以更好地应用。 10 In recent years, with the development of Internet technology, the construction of digital education resources of our country has made great achievements. Many universities have set up their own digital learning platforms, and digital teaching is playing an increasingly important role in education. Compared with the traditional way of teaching, the digital way has a lot of advantages. On one hand, digital teaching makes global sharing of teaching resources possible; on the other hand, it expands the learner’s study time and space to learn, allowing people to get access to the digital virtual schools through the Internet anytime and anywhere. These advantages make it possible for people to shift from one-time learning to lifelong learning. Section B 1 1 Main idea: College has never been magical for everyone. Major detail: More high school graduates don’t fit the pattern of college. 2 Main idea: We need to revise our attitudes and reform the system. Major detail: We only judge things based on our own college experiences. 3 Main idea: College education seems to have wasted time and accumulated debt Major detail: Close to 80 percent of new jobs can be performed by someone without a college degree. 2 1 C 2 D 3 C 4 A 5 D 6 B 7 B 8 A 4 1 enroll 2 revise 3 accumulate 4 accorded 5 evaluate 6 prime 7 confirm 8 shrinking 9 sufficient 10 recruit 5 1 bother to 2 is available to 3 been compelled to 4 described…as 5 exposed…to 6 rather than 7 have something to do with 8 for its own sake 61 A teacher, no matter how knowledgeable he is, cannot teach his students everything they want to know.

Java编程基础知识点汇总及习题集答案

J a v a编程基础知识点汇总及习题集答案 集团文件发布号:(9816-UATWW-MWUB-WUNN-INNUL-DQQTY-

目录 第一章 Java入门 (2) 第二章 Java基础 (5) 第三章条件转移 (14) 第四章循环语句 (20) 第五章方法 (26) 第六章数组 (33) 第七章面向对象 (42) 第八章异常 (63) 第一章 Java入门 知识点汇总 1、JAVA 三大体系 Java SE:(J2SE,Java2 Platform Standard Edition,标准版),三个平台中最核心的部分,包含Java 最核心的类库。 JavaEE:(J2EE,Java 2 Platform, Enterprise Edition,企业版),开发、装配、部署企业级应用,包含Servlet、JSP、JavaBean、JDBC、EJB、Web Service等。 Java ME:(J2ME,Java 2

Platform Micro Edition,微型版),用于小型电子设备上的软件开发。 2、JDK,JRE,JVM的作用及关系作用 ★JVM:保证Java语言跨平台 ★JRE:Java程序的运行环境 ★JDK:Java程序的开发环境 关系 ★JDK:JRE+工具 ★JRE:JVM+类库 3、JDK环境变量配置 path环境变量:存放可执行文件的存放路径,路径之间 用逗号隔开 classpath环境变量:类的运行路径,JVM在运行时通过classpath加载需要的类 4、重点掌握两个程序 :Java编译器工具,可以将编写好的Java文件(.java)编译成Java字节码文件(.class); :Java运行工具,启动Java虚拟机进程,运行编译器生成的字节码文件(.class) 5、一切程序运行的入口public static void main (String args []){ World!”); } 课堂笔记

Java语言程序设计基础教程习题解答

《Java语言程序设计基础教程》练习思考题参考答案

第1章 Java程序设计概述 练习思考题 1、 Java运行平台包括三个版本,请选择正确的三项:() A. J2EE B. J2ME C. J2SE D. J2E 解答:A,B,C 2、 Java JDK中反编译工具是:() A. javac B. java C. jdb D. javap 解答:D 3、 public static void main方法的参数描述是:() A. String args[] B. String[] args C. Strings args[] D. String args 解答:A,B 4、在Java中,关于CLASSPATH环境变量的说法不正确的是:() A. CLASSPATH一旦设置之后不可修改,但可以将目录添加到该环境变量中。 B. 编译器用它来搜索各自的类文件。 C. CLASSPATH是一个目录列表。 D. 解释器用它来搜索各自的类文件。 解答:A 5、编译Java Application源文件将产生相应的字节码文件,扩展名为() A. .java B. .class C. .html D. .exe 解答:B 6、开发与运行Java程序需要经过的三个主要步骤为____________、____________和____________。 7、如果一个Java Applet源程序文件只定义有一个类,该类的类名为MyApplet,则类MyApplet必须是______类的子类并且存储该源程序文件的文件名为______。 8、如果一个Java Applet程序文件中定义有3个类,则使用Sun公司的JDK编译器编译该源程序文件将产生______个文件名与类名相同而扩展名为______的字节码文件。 9、开发与运行Java程序需要经过哪些主要步骤和过程? 10、Java程序是由什么组成的?一个程序中必须要有public类吗?Java源文件的命名规则是怎么样的? 11、编写一个简单的Java应用程序,该程序在命令行窗口输出两行文字:“你好,很高兴学习Java”和“We are students”。

java基础考试题及答案

新员工考试 一、选择题(共30题,每题 2 分) 1. 下面哪些是合法的标识符?(多选题) A. $persons B. TwoUsers C. *point D. this E. _endline 答案A,B,E 分析Java 的标识符可以以一个Unicode 字符,下滑线(_),美元符($)开始,后续字符可以是前面的符号和数字,没有长度限制,大小写敏感,不能是保留字(this 保留字)。 2. 哪些是将一个十六进制值赋值给一个long 型变量?(单选题) A. long number = 345L; B. long number = 0345; C. long number = 0345L; D. long number = 0x345L 答案D 分析十六进制数以Ox开头,Io ng型数以L (大小写均可,一般使用大写,因为小写的 l 和数字1 不易区分)。 3. 下面的哪些程序片断可能导致错误? (多选题) A. String s = "Gone with the wind"; String t = " good "; String k = s + t; B. String s = "Gone with the wind"; String t; t = s[3] + "one"; C. String s = "Gone with the wind"; String standard = s.toUpperCase(); D. String s = "home directory"; String t = s - "directory"; 答案B,D 分析 A:String 类型可以直接使用+进行连接运算。 B:String 是一种Object ,而不是简单的字符数组,不能使用下标运算符取其值的某个元 素,错误。 C:toUpperCase()方法是String 对象的一个方法,作用是将字符串的内容全部转换为大写并返回转换后的结果(String 类型)。 D:String 类型不能进行减(- )运算,错误。 4. point x 处的哪些声明是句法上合法的? (多选题) cIass Person { private int a; pubIic int change(int m){ return m; } } pubIic cIass Teacher extends Person { public int b;

新视野大学英语(第三版)读写教程2第六单元练习答案

Unit 6 Section A 3 1 implement 2 rival 3 motivating 4 discarded 5 fluctuating 6 prejudiced 7 restore 8 enlightening 9 profit 10 investigate 4–ic strategic sympathetic -ion confirmation location reflection provision installation registration quote -ize sympathize criticize industrialize 5 1 sympathize 2 confirmation 3 strategic 4 installation 5 quote 6 sympathetic 7 criticize 8 location 9 reflection 10 industrialize 11 provision 12 registration 6 1 M 2 D 3 H 4 O 5 F 6 L 7 I 8 C 9 J 10 A 7 1 was attached to 2 be measured in 3 come in handy 4 clinging to 5 pay a big price 6 are exhausted from 7 impose on 8 revolve around 9极简主义是指去掉多余的,仅保留需要的部分。用最简单的话来说,极简的生活方式,就是生活得越简单越好,直到获得心灵的平静,这种简单既是精神上的,也是身体上的。这种生活方式会减轻压力,带来更多自由时间,并增强幸福感。极简主义者会说,他们生活得更有意义了,更从容了,极简的生活方式让他们着眼于生活中更重要的事物:朋友、爱好、旅游和体验。当然,极简主义并不意味着拥有物质财富从本质上来讲有什么不对。现在的问题似乎在于,我们往往太重视所拥有的东西,而常常抛弃了健康、人与人之间的关系、我们的热情、个人成长,以及帮助他人的愿望。极简主义除了在我们的日常生活中可以得到应用,还存在于很多创意领域,包括艺术、建筑、设计、舞蹈、电影、戏剧、音乐、时尚、摄影和文学等。 10 National Happiness Index (NHI) is an index that measures how happy people are. It is also a tool that measures the levels of economic development and people’s livelihood and happiness in a country or region. With the fast growth of Chinese economy, the Chinese government has been paying more and more attention to people’s living quality and the increase of happiness index. The government stresses improvement of its people’s livelihood, striving to improve their economic conditions and meet their growing material and cultural needs. Currently, the Chinese government advocates the unleashing of more reform dividends, with the aim of offering more real benefits to its people. All these measures will combine to effectively increase the NHI of our people. Section B 1 Because he thought he could get the jeans he wanted right away. 2 Since there were too many choices of jeans, the author simply didn’t know what particular one to choose. 3 He must feel headache and become impatient in this simple transaction. He probably even considered it nothing but torture. 4 Modern life provides people with more options than they used to have, and material choices are incredibly abundant, but do people feel happier? 5 People in modern times are not really happy even when they are surrounded with abundant material goods and so many options. 6 Too many options and considerable material possessions won’t necessarily bring people happiness and satisfaction. 7 Human beings are greedy by nature, nad the tendency of thinking “The more, the better” could

Java基础试题及其答案

Java试题 1) java程序中,main方法的格式正确的是()。(选择一项) a)static void main(String[] args) b)public void main(String[] args) c)public static void main(String[]s) d)public static void main(String[] args) 2)给定java代码,如下: public byte count(byte b1,byte b2){ return______; } 要使用这段代码能够编译成功,横线处可以填入()。(选择一项)a)(byte) (b1-b2) b)(byte) b1-b2 c) b1-b2 d) (byte) b1/b2 3)在Java中,在包下定义一个类,要让包下的所有类都可以访问这个类,这个类必须定义为()。(选择一项) a)protected b)private c)public d)friendly 4)在Java中,下列()语句不能通过编译。 (选择一项) a) String s= “join”+ “was”+ “here”; b) String s= “join”+3; “”+new Person() toString() c) int a= 3+5 d) float f=5+; double float 6)给定java代码如下,运行时,会产生()类型的异常。(选择一项) String s=null; (“abc”); a)ArithmeticException b)NullPointerException c)IOException d)EOFException 已到文件尾,再读取抛出 7) 在java中,()对象可以使用键/值的形式保存数据。(选择一项) a)ArrayList List 有序可重复 b) HashSet Set 无序不可重复同一对象是重复 的 c) HashMap Map(key/value)重复定义:hashCode、 equals(业务) d) LinkedList List 8)给定如下java代码,编译运行之后,将会输出()。 public class Test{ public static void main(String args[]){ int a=5;

Java程序设计实用教程_习题解答

习题 1 1.James Gosling 2.需3个步骤: 1)用文本编辑器编写源文件 2)使用Java编译器(javac.exe)编译源文件,得到字节码文件。 3)使用java解释器(java.exe)来解释执行字节码文件。 3.D:\JDK 1) 设置path 对于Windows 2000/2003/XP,右键单击“我的电脑”,在弹出的快捷菜单中选择“属性”,弹出“系统特性”对话框,再单击该对话框中的“高级选项”,然后单击“环境变量”按钮,添加系统环境变量path。如果曾经设置过环境变量path,可单击该变量进行编辑操作,将需要的值d:\jdk\bin加入即可(注意:修改系统环境变量path后要重新打开DOS窗口编译)。或在DOS窗口输入命令行: set path=d:\jdk\bin(注意:用此方法修改环境变量每次打开DOS窗口都需要输入该命令行重新进行设置)。 2) 设置classpath 对于Windows 2000/2003/XP,右键单击“我的电脑”,在弹出的快捷菜单中选择“属性”,弹出“系统特性”对话框,再单击该对话框中的“高级选项”,然后单击“环境变量”按钮,添加系统环境变量classpath。如果曾经设置过环境变量classpath,可单击该变量进行编辑操作,将需要的值d:\jdk\jre\lib\rt.jar;.;加入即可。或在DOS窗口输入命令行: set classpath= d:\jdk\jre\lib\rt.jar;.;。 4.(B)javac 5.Java源文件的扩展名是”.java”,Java字节码的扩展名是”.class” 6.Java应用程序主类的main申明(D)public static void main(String args[])

Java基础试题及答案

《Java面向对象程序设计》 姓名: 一、判断题(15’) 1.Java程序里,创建新的类对象用关键字new,回收无用的类对象使用关键字free。错 finalize()方法 2.对象可以赋值,只要使用赋值号(等号)即可,相当于生成了一个各属性与赋值对象相同的新对象。错方法赋值采用相应的方法 3.有的类定义时可以不定义构造函数,所以构造函数不是必需要写的。对4.类及其属性、方法可以同时有一个以上的修饰符来修饰。对 5.Java的屏幕坐标是以像素为单位,容器的左下角被确定为坐标的起点错6.抽象方法必须在抽象类中,所以抽象类中的方法都必须是抽象方法。错7.Final类中的属性和方法都必须被final修饰符修饰。错 8.最终类不能派生子类,最终方法不能被覆盖。对 9.子类要调用父类的方法,必须使用super关键字。错 10.一个Java类可以有多个父类。错 二、选择题(30’) 1、关于被私有保护访问控制符private protected修饰的成员变量,以下说法正确的是(C) A.可以被三种类所引用:该类自身、与它在同一个包中的其他类、在其他包中的该类的子类 B.可以被两种类访问和引用:该类本身、该类的所有子类 C.只能被该类自身所访问和修改 D.只能被同一个包中的类访问 2、关于被私有访问控制符private修饰的成员变量,以下说法正确的是(C)A.可以被三种类所引用:该类自身、与它在同一个包中的其他类、在其他包中的该类的子类 B.可以被两种类访问和引用:该类本身、该类的所有子类 C.只能被该类自身所访问和修改 D.只能被同一个包中的类访问 3、关于被保护访问控制符protected修饰的成员变量,以下说法正确的是(D)A.可以被三种类所引用:该类自身、与它在同一个包中的其他类、在其他包中的该类的子类 B.可以被两种类访问和引用:该类本身、该类的所有子类 C.只能被该类自身所访问和修改 D.只能被同一个包中的类访问 4、下列关于修饰符混用的说法,错误的是(D) A.abstract不能与final并列修饰同一个类 B. abstract类中不可以有private的成员 C.abstract方法必须在abstract类中

新视野大学英语第三版第二册读写教程2课后标准答案和翻译

Unit 1Language in mission Text A An impressive English lesson Ex.1 Understanding the text 1、Because he is tired of listening to his father and he is not interested in grammar rules. 2、 The civilization of Greece and the glory of Roman architecture are so marvelous and remarkable that they should be described at least in a brief account 。 however, what the student could do was only one single utterance : “whoa! ” without any any specific comment. 3、Because the schools fail to set high standards of language proficiency. They only teach a little grammar and less advanced vocabulary. And the younger teachers themselves have little knowledge of the vital structures of language. 4、Because teaching grammar is not an easy job and most of the students will easily get bored if it ’ s not properly dealt with. 5、He familiarized his son with different parts of speech in a sentence and discussed their specific grammatical functions including how to use adverbs to describe verbs. 6、Because the son had never heard about the various names and functions of words in an English sentence before. 7、The author uses “ road map ” and “ car”to describe grammar and vocabulary. Here, “road map” is considered as grammar and “ car” as vocabulary. 8、 Since the subjunctive mood his son used is a fairly advanced grammar structure, the interjection“ whoa! ”reflects the tremendous pride the father had toward his son 。 it also reflects the author ’s humor in using the word because it was once used by his student, though in two different situations and with two different feelings. Ex.3 Words in use 1.condense 2.exceed 3.deficit 4.exposure 5.asset 6.adequate https://www.doczj.com/doc/045683621.html,petent 8.adjusting 9.precisely 10.beneficial Ex.4 Word building -al/-ial:managerial/editorial/substance/survival/tradit ion/margin -cy :

JAVA入门练习50题(含答案)

题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? //这是一个菲波拉契数列问题 public class lianxi01 { public static void main(String[] args) { System.out.println("第1个月的兔子对数: 1"); System.out.println("第2个月的兔子对数: 1"); int f1 = 1, f2 = 1, f, M=24; for(int i=3; i<=M; i++) { f = f2; f2 = f1 + f2; f1 = f; System.out.println("第" + i +"个月的兔子对数: "+f2); } } } 【程序2】 题目:判断101-200之间有多少个素数,并输出所有素数。 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。 public class lianxi02 { public static void main(String[] args) { int count = 0; for(int i=101; i<200; i+=2) { boolean b = false; for(int j=2; j<=Math.sqrt(i); j++) { if(i % j == 0) { b = false; break; } else { b = true; } } if(b == true) {count ++;System.out.println(i );} } System.out.println( "素数个数是: " + count); } }

新视野大学英语第三版读写教程2课后翻译答案

Unit1中国书法 中国书法(calligraphy)是一门独特的艺术、是世界上独一无二的艺术瑰宝。中国书法艺术的形成,发展与汉文字的产生与演进存在着密不可分的关系。汉字在漫长的演变发展过程中,一方面起着交流思想、继承文化的重要作用,另一方面它本身又形成了一种独特的艺术。书法能够通过作品把书法家个人的生活感受、学识、修养、个性等折射出来,所以,通常有“字如其人”的说法。中国书法不仅是中华民族的文化瑰宝,而且在世界文化艺术宝库中独放异彩。 Chinese calligraphy is a unique art and the unique art treasure in the world. The formation and development of the Chinese calligraphy is closely related to the emergence and evolution of Chinese characters. In this long evolutionary process, Chinese characters have not only played an important role in exchanging ideas and transmitting culture but also developed into a unique art form. Calligraphic works well reflect calligraphers' personal feelings, knowledge, self-cultivation, personality, and so forth, thus there is an expression that "seeing the calligrapher's handwriting is like seeing the person". As one of the treasures of Chinese culture, Chinese calligraphy shines splendidly in the world's treasure house of culture and art. Unit2互联网 近年来,随着互联网技术的发展,我国的数字化教育资源建设取得了巨大的成就。很多高校建立了自己的数字化学习平台,数字化教学在教育中发挥着越来越大的作用。和传统教学方式相比,数字化教学方式有很大的优势。一方面,数字化教学使教学资源得以全球共享;另一方面,它拓展了学习者的学习时间和空间,人们可以随时随地通过互联网进入数字化的虚拟学校学习。这使得人类从接受一次性教育走向终身学习成为可能。 In recent years, with the development of Internet technology, the construction of digital education resources of our country has made great achievements. Many universities have set up their own digital learning platforms, and digital teaching is playing an increasingly important role in education. Compared with the traditional way of teaching, the digital way has a lot of advantages. On one hand, digital teaching makes global sharing of teaching resources possible on the other hand, it expands the learner's study time and space to learn, allowing people to get access to the digital virtual schools through the Internet anytime and anywhere. These advantages make it possible for people to shift from one-time learning to lifelong learning. Unit3 孝道(filial piety)是中国古代社会的基本道德规范(code of ethics)。中国人把孝视为人格之本、家庭和睦之本、国家安康之本。由于孝道是儒家伦理思想的核心,它成了中国社会千百年来维系家庭关系的道德准则。它毫无疑问是中华民族的一种传统美德。孝道文化是一个复合概念,内容丰富,涉及面广。它既有文化理念,又有制度礼仪(institutional etiquette)。一般来说,它指社会要求子女对父母应尽的义务,包括尊敬、关爱、赡养老人等等。孝道是古老的"东方文明"之根本。 Filial piety is the basic code of ethics in ancient Chinese society. Chinese people consider filial piety as the essence of a person's integrity, family harmony, and the nation's well-being. With filial piety being the core of Confucian ethics, it has been the moral standard for the Chinese society to maintain the family relationship for thousands of years. It's undoubtedly a traditional Chinese virtue. The culture of filial piety is a complex concept, rich in content and wide in range. It includes not

相关主题
文本预览
相关文档 最新文档