重庆大学网络教育学院《Java程序设计》课程作业一二三答案

2022年4月821:37:40 发表评论 77 views

文档名:Java程序设计.docx

下载次数:10次

价格:15.00元

电大之家提醒您:
1、课程答案都是汇总在一个word文件,不区分形考任务1234,打开文件搜索题目找参考答案。 请购买前,核对下面题目无误后再购买,电脑端按CTRL+F键进行核对题目,移动端通过顶部切换成“页内查”来核对题目;3、搜寻免费答案花费的时间成本更高!参考答案整理不易,感谢你的支持!


高分通过,扫码咨询
微信:homework52

设 i,j 为类 x 中定义的 double 型变量名,下列 x 类的构造函数中不正确的是( )

A、

double x(double k )
{
i=k;
return i;
}



B、

x(double m, double n )
{
i=m;
j=n;
}



C、

x( )
{
i=0;
j=0;
}



D、

x(double k )
{
i=k;
}

package语句的作用是( )

A、

引入一个包

B、

创建一个包

C、

既能引入一个包,又能创建一个包

D、

以上皆不对

关于下列程序结果正确的是( )

public class MyClass{

static int i;

public static void main(String argv[]){

System.out.println(i);

}

}

A、

Error Variable i may not have been initialized

B、

Null

C、

1

D、

0

在某类的子类中,下述方法中必须要实现的方法是( )

A、

Public double methoda();

B、

Static void methoda (double d1);

C、

Public native double methoda();

D、

Abstract public void methoda();

以下哪个表达式是不合法的( )

A、

String x=”Hello”; int y=9; x+=y;

B、

String x=”Hello”; int y=9; if(x= =y) { };

C、

String x=”Hello”; int y=9; x=x+y;

D、

String x=null; int y=(x!=null)&&(x.length()>0) ? x.length() : 0;

下列选项中为java关键字的是( )

A、

default

B、

Run

C、

Integer

D、

implement

下列哪个方法可以获得一个事件的ID号( )

A、

int getID()

B、

String getSource()

C、

int returnID()

D、

int eventID()

给定File f=new File("aa.txt");可以实现向文件尾部读写的是( )。

A、

RandomAccessFile f1=new RandomAccessFile(f,"r");

B、

RandomAccessFile f1=new RandomAccessFile(f,"a");

C、

RandomAccessFile f1=new RandomAccessFile(f,"rw");

D、

RandomAccessFile f1=new RandomAccessFile(f,"w");

若所用变量都已正确定义,以下选项中,非法的表达式是( )。

A、

a!=4||b==1;

B、

'a' % 3;

C、

'a'=1/2;

D、

'A' + 32;

一个类的成员变量如果要使其可以被同一个包中其它类访问,应该选取的修饰符为( )

A、

protected

B、

public

C、

缺省(没有)

D、

private

传递给public static void main方法的String数组的下标为0的元素为( )

A、

应用程序的名称

B、

所传递参数的个数

C、

所传递参数中的第一个

D、

以上均不对

以下由do-while语句构成的循环执行的次数是( )

int k = 0;

do {

++k;

}while ( k < 1 );

A、

一次也不执行

B、

执行1次

C、

无限次

D、

有语法错,不能执行

下列说法不正确的是( )

A、

java语言里的线程是没有优先级的

B、

String类在java.lang包中

C、

java语言支持类的序列化

D、

能序列化的类必须实现java.io.Serializable接口

如果有类Person和其子类Man和Woman,则如果程序中出现语句Woman w=new Man();下列说法正确的是( )。

A、

语句错误

B、

语句正确

C、

编译正确但运行错误

D、

以上均不对

容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改变? ( )

A、

CardLayout

B、

FlowLayout

C、

BorderLayout

D、

GridLayout

关于线程的下列说法正确的是( )

A、

线程只能通过继承类Thread创建.

B、

执行suspend方法将使线程停止并不能被重新start.

C、

线程与进程实际是同一个概念.

D、

线程的终止可以通过两种方式实现:自然撤销或被停止.

使用FlowLayout作为布局管理器,则向容器中添加对象component的正确方法是( )

A、

add(component);

B、

add("Center", component);

C、

add(x, y, component);

D、

set(component);

main方法是Java Application程序执行的入口点,关于main方法的方法头以下哪项是合法的?( )

A、

public static void main()

B、

public static void main(String[ ] args)

C、

public static int main(String[ ] arg)

D、

public void main(String arg[ ])

下列哪个选项不会出现编译错误?( )

A、

float f = 1.3;

B、

char c = "a";

C、

byte b = 257;

D、

int i = 10;

给定以下程序段

insert code public class foo {

public static void main (String[] args) throws Exception {

printWriter out = new PrintWriter (new java.io.outputStreamWriter (System.out), true) ;

out.printIn(“Hello”);

}

}

要使程序能正确运行,在insert code处必须添加( )语句

A、

import java.io.PrintWriter;

B、

include java.io.PrintWriter;

C、

import java.io.OutputStreamWriter;

D、

include java.io.OutputStreamWriter;

下列哪个类或接口是类FilterOutputStream 的构造方法的输入参数( )

A、

InputStream

B、

OutputStream

C、

File

D、

RandomAccessFile

以下程序

boolean a=false;

boolean b=true;

boolean c=(a&&b)&&(!b);

int result=c==false?1:2;

执行完后,c与result的值是( )

A、

c=false;result=1;

B、

c=true;result=2;

C、

c=true;result=1;

D、

c=false;result=2;

通过下列( )I/O类可以实现对文件类File的添加,更新操作。

A、

RandomAccessFile

B、

Outputstream

C、

DataOutputstream

D、

InputStream

Java语言是( )。

A、

面向问题的解释型高级编程语言

B、

面向机器的低级编程语言

C、

面向过程的编译型高级编程语言

D、

面向对象的解释型高级编程语言

下面哪些赋值语句是错误的?( )

A、

float f = 11.1;

B、

double d = 5.3E12;

C、

char c ='\r';

D、

Boolean b=true;

下列语句中错误的是( )

A、

StringBuffer sb=new String(‘a’)

B、

StringBuffer sb1=new StringBuffer();

C、

StringBuffer sb2=new StringBuffer(20);

D、

StringBuffer sb3=new StringBuffer(“sss”);

下列二维数组定义不正确的是( )

A、

int []a[] = new int[10][10];

B、

int a[10][10] = new int[][];

C、

int a[][] = new int[10][10];

D、

int [][]a = new int[10][10];

在单一文件中import、class和package的正确出现顺序是( )

A、

package, import, class

B、

class, import, package

C、

import, package, class

D、

package, class, import

编译,运行下列代码后的结果是( )

public class Test {

public static void main (String args []) {

int age;

age = age + 1;

System.out.println("The age is " + age);

}

}

A、

编译,运行后没有输出

B、

编译,运行后输出:The age is 1

C、

能通过编译,但运行时产生错误

D、

不能通过编译

如果要向文件file.txt中添加数据,应如何构建输出流( )

A、

OutputStream out=new FileOutputStream(“file.txt”);

B、

OutputStream out=new FileOutputStream(“file.txt”, “append”);

C、

FileOutputStream out=new FileOutputStream(“file.txt”, true);

D、

FileOutputStream out=new FileOutputStream(new file(“file.txt”));

构造函数在( )时被调用

A、

类定义时

B、

使用对象的属性时

C、

使用对象的方法时

D、

对象被创建时

如果通过命令行java myprog good morning 运行下列程序,结果正确的是( )。  重庆大学网络教育学院《Java程序设计》课程作业一二三答案

A、

myprog

B、

good

C、

morning

D、

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at myprog.main(myprog.java:4)

如果一个程序段中有多个catch,则程序会按下列哪种情况执行( )

A、

找到合适的异常类型后继续执行后面的catch

B、

找到每个符合条件的catch都执行一次

C、

找到合适的异常类型后就不再执行后边的catch

D、

对每个catch都执行一次

既能作为类的修饰符, 也能作为类成员的修饰符的是( )

A、

public

B、

extends

C、

float

D、

static

下列语句执行后,a的值是( ) int a=13; a%=a/5;

A、

3

B、

13

C、

169

D、

1

假定组件List定义为List l=new List(5,true),则下列描述正确的是( )

A、

该列表的最大容量为5

B、

该列表可显示5行,并且为多选模式

C、

该列表可显示5行,并且为单选模式

D、

以上均不对

下面是有关子类继承父类构造函数的描述,其中正确的是( )

A、

创建子类的对象时,先调用子类自己的构造函数,然后调用父类的构造函数.

B、

子类无条件地继承父类不含参数的构造函数.

C、

子类必须通过super关键字调用父类的构造函数

D、

子类无法继承父类的构造函数.

下列类头定义中,错误的是( )

A、

class x{}

B、

public x extends y{ }

C、

public class x extends y{}

D、

class x extends y implements y1 { }

给定下列程序段: public void method(){ (1) if (someTestFails()){ (2) } (3) }如果要使该方法抛出一个IOException当且仅当someTestFails()返回值为真时,则下列说法正确的是( )

A、

在(1)处添加 IOException e;

B、

在(2)处添加 throw e;

C、

在(2)处添加throw new IOException( );

D、

在(3)处添加throw new IOException( );

paint()方法使用( )作为起输入参数。

A、

Graphics

B、

Graphics2D

C、

String

D、

Color

下列关于事件监听器说法正确的是( )

A、

一个组件一次只能设置一个监听器

B、

时间监听器可以从组件中删除

C、

只要设置一个事件监听器就可对组件中的多种事件进行响应

D、

进行事件处理时,必须使用try-catch结构

下列说法错误的是( )。

A、

Java Application命名必须与公共类名相同

B、

自定义Applet通常是类Applet的子类

C、

Applet中也可以有main()方法

D、

一个Java Application文件中可以定义多个类

下列方法定义中,正确的是( )

A、

int x( ){ char ch='a'; return (int)ch; }

B、

void x( ){ ...return true; }

C、

int x( ){ ...return true; }

D、

int x( int a, b){ return a+b; }

关于事件监听器下述说法正确的是( )

A、

一个对象最多可以设置一个监听器

B、

每个监听器的返回值可以用于激活其它的监听器

C、

如果一个对象可设置多个监听器,则每个监听器执行顺序是固定的.

D、

在AWT中, 每个监听器的方法都必须取得一个输入参数,该参数是java.awt.AWTEvent 子类的一个实例.

给出下列代码段:

if(x>4){

System.out.println(“Test 1”);

} else if(x>9){

System.out.println(“Test 2”);

} else {

System.out.println(“Test 3”);

}

哪一个范围的x取值可以产生输出信息:”Test 3” ( )

A、

小于0

B、

5到9之间

C、

大于等于10

D、

以上均不对

下式中给字符串数组正确赋值的语句是( )。

A、

String temp [] = new String {"j", "a", "z"};

B、

String temp [] = { "j " " b" "c"};

C、

String temp = {"a", "b", "c"};

D、

String temp [] = {"a", "b", "c"};

String s=”Example String”;下列对s的操作中( )是错误的

A、

int i=s.length();

B、

s[3]=”x”;

C、

String short_s=s.trim();

D、

String t=”root”+s;

当某区域被毁坏或需要清除时,AWT会自动调用下列哪个方法( )

A、

paint()

B、

repaint()

C、

update()

D、

destoy()

可以替换一个Container对象布局的方法( )。

A、

setLayout(aLayoutManager);

B、

addLayout(aLayoutManager);

C、

layout(aLayoutManager);

D、

setLayoutManager(aLayoutManager);

Java应用中main()方法的参数形式正确的是( )

A、

String args

B、

String ar[]

C、

Char args[][]

D、

DStringBuffer arg[]

以下赋值语句中( )是错误的.

A、

float f=1/3;

B、

int i=1/3;

C、

float f=1.01;

D、

double d=999d;

下列选项不是类修饰符protected特征的是( )

A、

可被本类访问

B、

可被子类访问

C、

可被同一包中其它类访问

D、

可被不同包中非子类访问

Java中合法标识符是( )。

A、

3d_game

B、

%passwd

C、

userName

D、

this

下列哪个选项不能使当前线程停止执行?( )

A、

一个异常被抛出

B、

线程执行了sleep()调用

C、

高优先级的线程处于可运行状态

D、

当前线程产生了一个新线程

下列标识符不合法的是( )

A、

2variable

B、

variable2

C、

_whatavariable

D、

_3_

类public class returnIt{

returnType methodA(byte x, double y) {

return x/y * 2;

}

}

中的方法methodA( )方法的返回值类型为( )

A、

Int

B、

Byte

C、

Short

D、

double

为了使包sos在当前程序中可见,可以使用的语句是( ).

A、

import sos.*

B、

package sos.*

C、

include sos

D、

sos package

下面关于Applet的说法正确的是( )

A、

Applet也需要main方法

B、

自定义Applet可以继承自java.awt.Applet

C、

Applet能访问本地文件

D、

Applet程序不需要编译

编译并运行下列程序的正确结果是( )

public class EqualsTest{

public static void main(String args[]){

Object A=new Long(7);

Long L=new Long(7);

if(A.equals(L)) System.out.println("Equal");

else System.out.println("Not Equal");

}

}

A、

Equal.

B、

Not Equal

C、

.编译错误

D、

以上均不对.

如果一个类对象要永久保存,则必须实现接口( )。

A、

Runnable

B、

Enumeration

C、

Serializable

D、

Object

关于下列程序

public class Q {

public static void main(String argv[]){

int anar[]= new int[]{1,2,3};

System.out.println(anar[1]);

}

}

以下结论正确的是( )

A、

发生编译错误

B、

1

C、

2

D、

数组长度未指定

下列对常量MAX定义正确的是( )

A、

public int MAX =100;

B、

static int MAX =100;

C、

final public int MAX =100;

D、

public final static int MAX =100;

StringBuffer str=new StringBuffer(25);
String s=”Hello”,
若执行语句str.append(s)后,str.length()和str.capacity()的返回值为( )

A、

5,5

B、

25,5

C、

5,25

D、

25,25

下列InputStream构造方法正确的是( )

A、

InputStream in=new FileReader(“file.txt”);

B、

InputStream in=new FileInputStream(“file.txt”);

C、

InputStream in=new InputStreamFileReader (“file.txt”, “read”);

D、

FileInputStream in=new FileReader(new File(“file.txt”));

给定程序如下

public static void main(String args[]) {

Float f=new Float(4.2f);

Float c;

Double d=new Double(4.2);

float fl=4.2f;

c=f;

}

下列选项中( )的值为真.

A、

f.equals(d)

B、

c=f

C、

c==d

D、

c.equals(f)

下列哪个不是整数类型的变量( )

A、

-10

B、

045

C、

0xa1

D、

67f

在一个应用程序中有如下定义:int a[]={1,2,3,4,5,6,7,8,9,10};为了打印输出数组a的最后一个元素,下面正确的代码是( )

A、

System.out.println(a[10]);

B、

System.out.println(a[9]);

C、

System.out.println(a[a.length]);

D、

System.out.println(a[8]);

给定程序

class Base{ public void Base() {

System.out.println("Base");

}

}

public class In extends Base{

public static void main(String argv[]) {

In i=new In();

}

}

则下列说法正确的是( )

A、

出现编译错误

B、

编译通过但是无输出信息

C、

输出”Base”

D、

运行时产生异常

在某个类A中存在一个方法:void GetSort(int x),以下能作为这个方法的重载的声明的是( )

A、

void GetSort(float x)

B、

int GetSort(int y)

C、

double GetSort(int y)

D、

void Get(int x,int y)

若已定义 byte[ ] x= {11,22,33,-66} ; 其中0≤k≤3,则对x数组元素错误的引用是( )。

A、

x[5-3]

B、

x[k]

C、

x[k+5]

D、

x[0]

类System下列包( )中。

A、

java.util

B、

java.io

C、

java.awt

D、

java.lang

下列哪个标识符不是Java中的保留字( )

A、

if;

B、

then;

C、

goto;

D、

case;

设 x,y 均为已定义的类名,下列声明对象x1的语句中正确的是( )

A、

public x x1= new y( );

B、

x x1=x( );

C、

x x1=new x( );

D、

int x x1;

假定有一个可能引起异常的方法,用什么方式告诉方法的调用者要捕获该异常?( )

A、

throw Exception

B、

throws Exception

C、

new Exception

D、

不用特别指定

用于定义类成员的访问控制权的一组关键字是( )

A、

class, float, double, public

B、

float, boolean, int, long

C、

char, extends, float, double

D、

public, private, protected

下列哪种情况无法使当前线程停止执行( )

A、

线程执行过程中的异常被抛出发生

B、

线程执行了sleep()方法.

C、

产生了一个新线程

D、

具有更高优先级的线程准备就绪

给出下列声明String s=”Example”,则下列选项中( )不是合法的代码

A、

S[3]=”x”;

B、

int I=s.length();

C、

String t=”For”+s;

D、

String t=s.toLowerCase();

下列语句不正确的是( )。

A、

int a[][]=new int[][3];

B、

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

C、

String s[][]=new String[2][];

D、

String s[][]={{"can","I"},{"help","you"}};

如果String s1=“Chongqing”,则运行代码String s3=s1.substring(2,4)后s3的值为()

A、

on

B、

ngq

C、

hon

D、

ho

执行下列语句String foo = “ABCDE”; foo.substring(3); foo.concat(“XYZ”);后,变量foo的值为( )

A、

ABCDE

B、

ABCXYZ

C、

ABCDEXYZ

D、

CDEXYZ

给定ActionEvent,下列哪个方法可以识别出受改事件影响的对象( )

A、

public class getClass()

B、

public Object getSource()

C、

public Component getSource()

D、

public Component getTarget()

如果有Boolean a=new Boolean(“yes”),则a.booleanValue( )值为()

A、

yes

B、

“yes”

C、

true

D、

false

声明公用的abstract方法的正确格式是:()

A、

public virtual add( )

B、

public abstract void add( ){ }

C、

public abstract add( )

D、

public abstract void add( )

欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的 ? ( )

A、

List myList=new List( );

B、

List myList=new ArrayList( );

C、

ArrayList myList=new List( );

D、

ArrayList myList=new Object( );

下列哪个是接口MouseMotionListener的方法( )

A、

public boolean MouseMoved(MouseMotionEvent)

B、

public boolean mouseMoved(MouseEvent)

C、

public void mouseMoved(MouseMotionEvent)

D、

public void mouseMoved(MouseEvent)

public class sumof10
{
public static void main(String args[])
{
int I,sum;
sum=0;
I=1;
do
{
sum+=I; I++;
}
while (I<=10);
System.out.println(“sum=”+sum);
}
}

对象和类是同一个概念。

class test

{

public static void main(String args[])

{

int x=4,j=0;

switch(x)

{

case 1: j++;

case 2: j++;

case 3: j++;

case 4: j++;

case 5: j++;

break;

default: j++;

}

System.out.println(j);

}

}

public class Leaf{
private int i=0;
Leaf increment( ){
i++;
return this;
}
void print( ){
System.out.println(“i=”+i);
}
public static void main(String args[]){
Leaf x=new Leaf( );
x.increment( ).increment( ).increment( ).print( );
}
}

public class test

{

public static void main(String a[])

{ StringBuffer s=new StringBuffer("Java");

String c=new String("Java");

Hello(s,c);

System.out.println(s+c);

}

public static void Hello(StringBuffer s, String c)

{

s.append("C");

c.replace(''A'',''D'');

}

}

类RandomAccessFile提供了对随机文件访问的支持.

class Mystery

{

private long val;

public Mystery(long v)

{

val = v;

}

public static void main(String args[])

{

Mystery x = new Mystery(10L);

Mystery y = new Mystery(10L);

Mystery z = y; long a = 10L;

int b = 10;

System.out.println("the value1="+(y==z));

System.out.println("the value2="+(y==x));

}

}

import java.io.*;

import java.net.*;

public class Test

{

public static void main(String args[]) throws Exception

{

URL url=new URL(“http://www.163.com:80/news.html”);

System.out.println(“protocol=”+url.getProtocol());

System.out.println(“host=”+url.getHost());

System.out.println(“filename=”+url.getFile());

System.out.println(“path=”+url.getPath()); } }

class Test

{

public static void add3(Integer i)

{

int val=i.intValue();

val+=3; i=new Integer(val);

}

public static void main(String args[])

{

Integer i=new Integer(0);

add3(i);

System.out.println(i.intValue());

}

}

文件file.txt的内容为: How are you ?

import java.io.*;
public class Test{
public static void main(String args[]) throws IOException{
File inputfile=new File(“file.txt”);
FileReader in=new FileReader(inputfile);
int c;
while ((c=in.read())!= -1) { if(c==’’) {
System.out.println();
continue;
}
System.out.print ((char)c);
}

in.close();
}
}

public class test

{

static StringBuffer sb1=new StringBuffer("Hello");

static StringBuffer sb2=new StringBuffer("Hello");

public static void main(String args[])

{

aMethod(sb1,sb2);

System.out.println("sb1 is "+sb1);

System.out.println("sb2 is "+sb2);

}

public static void aMethod(StringBuffer sb1,StringBuffer sb2)

{

sb2.append(" there");

sb1=sb2;

}

}

class Base extends Object

{

String objType;

public Base()

{

objType="I am a Base type";

System.out.println(objType);

}

}

public class Test extends Base{ public Test()

{

objType="I am a Derived type";

System.out.println(objType);

}

public static void main(String args[])

{

Test D=new Test();

}

}

class A

{

public String toString()

{

return "4";

}

}

class B extends A

{

public String toString()

{

return super.toString()+"3";

}

}

public class test

{

public static void main(String args[])

{

B b=new B();

System.out.println(b.toString());

}

}

public class test{ 

 static int arr[] ={1,2,3,4,5};
 public static void main(String args[])
 {
 System.out.println(arr[]);
}
}

public class Test

{

public static void main(String args[])

{

Test d=new Test(); d.divide(4,0);

}

public void divide(int a, int b) {

try

{

int c = a / b;

}

catch (Exception e)

{

System.out.print("Exception ");

}

finally

{

System.out.println("Finally");

}

}

}

interface Foo
{
int k=0;
 }
 public class test implements Foo
{
public static void main(String args[])
{
 int i;
test t =new test();
 i=t.k;
 i=test.k;
 i=Foo.k;
System.out.println(i);
}
 }

public class SwitchTest

{

public static void main (String []args)

{

System.out.println(“value =” +switchIt(4));

}

public static int switchIt(int x)

{

int j = 1;

switch (x)

{

case 1: j++;

case 2: j++;

case 3: j++;

case 4: j++;

case 5: j++;

default:j++;

}

return j + x;

}

}

public class Calc
 {
public static void main (String args [])
 {
 int total = 0;
 for (int i = 0, j = 10; total > 30; ++i, --j)
{
System.out.println(" i = " + i + " : j = " + j);
 total += (i + j);
}
System.out.println("Total " + total);
 }
 }

public class test

{

public static void main(String[] args)

{

StringBuffer a=new StringBuffer("A");

StringBuffer b=new StringBuffer("B");

operate(a,b);

System.out.println(a+","+b);

}

public static void operate(StringBuffer x, StringBuffer y)

{

x.append(y);

y=x;

}

}

import java.io.* ;
public class Reverse{
public static void main(String args[ ]) {
int i , n =5 ;

int a[ ] = new int[5];
for ( i = 0 ; i < n ; i ++ )

try {
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
a[i] = Integer.parseInt(br.readLine( ));
}
catch ( IOException e ) { } ;
for ( i = n-1 ; i >= 0 ; i-- )

System.out.print(a[i]+" ");
System.out.println( );
}
}
如果从键盘输入1 2 3 4 5 则运行结果为:

import java.io.*;

public class test

{

public static void main(String argv[])

{

test m=new test();

System.out.println(m.amethod());

}

public int amethod()

{

try

{

FileInputStream dis=new FileInputStream("Hello.txt");

}

catch (FileNotFoundException fne)

{

System.out.println("No such file found");

return -1;

}

catch(IOException ioe)

{

}

finally{ System.out.println("Doing finally");

}

return 0;

}

}

如果文件Hello.txt并不存在,则运行结果是



public class EqualsTest

{

public static void main(String args[])

{

Long LA=new Long(7);

Long LB=new Long(7);

if(LA==LB) System.out.println("Equal");

else System.out.println("Not Equal");

}

}

public class test

{

public static void main(String argv[])

{

boolean b1 = true;

if((b1 ==true) || place(true))

{

System.out.println("Hello Crowle");

}

}

public static boolean place(boolean location)

{

if(location==true)

{

System.out.println("Borcetshire");

}

System.out.println("Powick");

return true;

}

}

public class demo
{
public static void main(String args[])
{
int bookno=0;
while (bookno<=100)
{
 bookno+=10;
if (bookno==40) break;
System.out.println(“the bookno is”+bookno);
 }
System.out.println(“This is the end”);
}
 }

class Base

{

int x=3;

public Base() {} public void show()

{

System.out.println(" The value is " +x);

}

}

class Derived extends Base

{

int x=2;

public Derived() {} public void show()

{

System.out.println(" The value is " +x);

}

}

public class test

{

public static void main(String args[])

{

Base b = new Derived();

b.show();

System.out.println("The value is "+b.x);

}

}

import java.awt.Graphics; import java.applet.Applet;

public class ttt extends Applet

{

public void paint( Graphics g )

{

int count, xPos = 25;

for ( count = 1; count <= 10; count++ )

{

if ( count == 8 ) break;

g.drawString( " " + count, xPos, 25 );

xPos += 10;

}

}

}

问题:程序的输出结果是什么?

public class test

{

public static void main(String args[])

{

int i=9;

switch (i)

{

default: System.out.println("default");

case 0: System.out.println("zero");

break;

case 1: System.out.println("one");

case 2: System.out.println("two");

}

}

}

public class test

{

public static void main(String ar[])

{

int j=10;

method(j);

amethod(j);

System.out.println(j);

}

public static void method(int j) { j++; } public static void amethod(int j) { j++; }

}

public class Test

{

public static void main(String[] args)

{

String foo=args[0];

String bar=args[1];

String baz=args[2];

System.out.println(baz);

}

}

如果执行语句 java Test Red Green Blue 后结果为

public class Test

{

public static void main(String args[])

{

int x = 2; switch (x)

{ case 1: System.out.println(1);

case 2: case 3: System.out.println(3);

case 4: System.out.println(4);

}

}

}

class Myexception extends Exception

{

Myexception ()

{

super();

}

Myexception(String msg)

{

super(msg);

}

}

public class Test

{

public static void main(String args[])

{

try

{

throw new Myexception(“自定义异常”);

}

catch(Myexception e)

{

System.out.println(e.getMessage());

}

}

}

class Mystery

{

String s="original";

public static void main(String[] args)

{

Mystery m=new Mystery();

m.go();

}

void Mystery()

{

s="constructor";

}

void go()

{

System.out.println(s);

}

}

class Sum
 {
int n;
float f()
{
 float sum=0;
 for(int i=1;i<=n;i++) sum=sum+i;
return sum;
 }
}
 class Average extends Sum
{
 int n;
 float f()
 {
 float c;
super.n=n;
c=super.f();
 return c/n;
}
 float g()
 {
float c;
 c=super.f();
 return c/2;
}
 }
 public class Cala
 {
public static void main(String args[]) {Average aver=new Average();
 aver.n=10;
 float result_1=aver.f();
 float result_2=aver.g();
 System.out.println("result_1="+result_1);
System.out.println("result_2="+result_2);
}
}

public class test

{

String s1 = "Initialized at definition";

String s2;

public test(String s2i)

{

s2 = s2i;

}

public static void main(String args[])

{

test si =new test("Initialized at construction");

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

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

}

}

public class student

{

String name;

int age;

student()

{

this("default",20);

}

student(String a1,int a2)

{

name=a1;

age=a2;

}

public static void main(String args[])

{

student s1=new student();

System.out.println("name="+s1.name+"age="+s1.age);

}

}

public class test{

public static void main(String args[]){

String s = null;

s.toString();

try { s.toString(); }

catch(Exception e){

System.out.println("Caught exception " + e);

}

}

}

public class test

{

public static void main(String args[])

{

String name[] = {"Killer","Miller"};

String name0 = "Killer";

String name1 = "Miller";

swap(name0,name1);

System.out.println(name0+"," +name1);

swap(name);

System.out.println(name[0]+"," +name[1]);

}

public static void swap(String name[])

{

String temp;

temp=name[0];

name[0]=name[1];

name[1]=temp;

}

public static void swap(String name0,String name1)

{

String temp;

temp=name0;

name0=name1;

name1=temp;

}

}

什么是对象?如何创建一个对象?

阅读题下面的程序段,回答以下问题.

if ( x < 5 ) System.out.print(" one ");

else {

if ( y < 5 ) System.out.print(" two ");

else System.out.println(" three ");

}

问题: 1)若执行前 x=6, y=8,该程序段输出是什么? 2)若执行前 x=1, y=8,该程序段输出是什么?

说明 while 与 do…while 语句的差异

方法的覆盖与方法的重载有何不同?

什么是接口和抽象类,它们之间的区别是什么?

消息的基本构成?

实例变量和类变量的区别是什么?

类System和Runtime分别具有什么作用?

简述线程与进程的区别。

String类与StringBuffer类的主要区别是什么?

线程与进程相比,它们的区别是什么?

什么是Applet,如何运行一个Applet?

说明在数据类型转换中,什么是隐式类型转换?什么是显示类型转换?

Applet中方法init(),start(),stop()和destroy()的作用?

使用socket进行通讯的基本步骤是什么?

数据报通信和流式通信的区别是什么?

说明修饰符private,public,protected,缺省的作用范围差异.

指出运算符“==”和方法equals()在判断题对象是否相等上的区别?

如何构造一个线程(两种方法)?

简述Java的异常处理机制?

简述Java程序的执行过程。

什么是串行化,如何进行串行化?

谈final, finally, finalize的区别.

一个URL有哪几部分组成?

说明Java程序为什么具有可移植性?

将下列程序改为功能相同但不用break的语句形式.

public class test {

public static void main(String[] args) {

int i,sum;

for(i=1,sum=0; ; i++,sum+=i) if(i>10)break;

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

}

}

给定一个字符串数组String f[] = {"ab", "bc", "cd", "de", "ef"}; 编程实现从该数组中查找用户指定字符串位置的功能,用户指定的字符串由命令行参数输入。

用if 嵌套编写求解下述函数的程序,给定 x 输出 y 值
. x (0≤x<10) y= x2+1 (10≤x<20) x3+x+1 (20≤x<30 )

将一个正整数分解质因数。例如:输入 90,打印出 90=2*3*3*5。

编写一个程序,接受用户从键盘输入的10个整数,并输出这10个整数的最大值和最小值。

重庆大学网络教育学院《Java程序设计》课程作业一二三答案

编程Java程序,实现文本文件c:\test.txt的读入并显示功能.

编写一个java程序将字符串”Mary was a ”改为”Mary had a book.”

编写程序求所有指定浮点数的平均值,要求所有浮点数均通过命令行参数传入(如java test 11.1 22.2 33.3 44.4)。

重庆大学网络教育学院《Java程序设计》课程作业一二三答案

设计一Applet,计算数组a[] = { 1, 3, 5, 7, 9, 10 }中各元素的和。

编写程序使用类StringBuffer的replace方法将字符串”Mary was a ”改为”Mary had a book.”

编程求出个位数为6,且能被3整除的5位整数共有多少个?

重庆大学网络教育学院《Java程序设计》课程作业一二三答案

编写一个程序,获取10个1~20的随机数,要求随机数不能重复。

编写程序删除指定文件,要求文件名通过main方法的参数传入.

编写一个应用程序,完成文件的拷贝功能,文件名从命令行得到.

编程计算 1/1+1/2+1/3+...+1/100 的值

设计一个Applet,在该Applet中实现计算学生成绩的功能:如果成绩大于90,输出优,如果成绩大于70小于90,输出良,如果成绩大于60小于70,输出及格,否则输出不及格.

编程将键盘输入的数据拷贝当前路径下test.txt中,如果遇到quit就结束程序。

编写程序利用String中的已有函数将字符串abcABC123中的大写转换为小写,小写转换为大写.

重庆大学网络教育学院《Java程序设计》课程作业一二三答案

编写程序将任意三个变量a,b,c中的值进行交换,使得变量a的值最小,b其次,c的值最大.

通过键盘传入一个数,判断题该数是不是素数(不能被1和自身整除的数).

class Sum
 {
int n;
float f()
{
 float sum=0;
 for(int i=1;i<=n;i++) sum=sum+i;
return sum;
 }
}
 class Average extends Sum
{
 int n;
 float f()
 {
 float c;
super.n=n;
c=super.f();
 return c/n;
}
 float g()
 {
float c;
 c=super.f();
 return c/2;
}
 }
 public class Cala
 {
public static void main(String args[]) {Average aver=new Average();
 aver.n=10;
 float result_1=aver.f();
 float result_2=aver.g();
 System.out.println("result_1="+result_1);
System.out.println("result_2="+result_2);
}
}

下列代码不能正确编译的原因是什么?

class A

{

public static void main(String args[])

{

B b=new B();

b.x=5;

}

}

class B

{

private int x;

Show()

{

System.out.println(x);

}

}

public class test

{

public static void stringReplace(String text)

{

text.replace(''a'',''e'');

}

public static void bufferReplace(StringBuffer text)

{

text=text.append("s");

}

public static void main(String args[])

{

String textString=new String("china");

StringBuffer textBuffer=new StringBuffer("china");

stringReplace(textString);

bufferReplace(textBuffer);

System.out.println(textString+textBuffer);

}

}

import java.awt.*;

import java.applet.*;

public class Test51` extends Applet

{

float[ ] x ={1.2, 3.4, 5.6, 7.8};

public void paint(Graphics g){

int s=0;

for( int i = 0; i < x.length; i++ ) s += (int)x[i];

g.drawString(" " + s, 30, 60);

}

}

问题: 1)程序的输出结果是什么? 2)方法paint()中的循环体 s += (int)x[i]; 能写为 s +=x[i]; 吗? 为什么?

编程实现从键盘输入字符串,并统计其中数字字符个数的功能

 

创建一个Applet,要求在init方法中向该applet添加一个文本输入区组件,该文本输入区中显示字符为“你好”,行数为10,列数为15.

Java语言支持类的序列化.( )

正确

错误

java语言中的逻辑变量可以和整型变量相互强制转换。

正确

错误

字符串 "\'a\'" 的长度是5.( )

正确

错误

数组的下标从1开始计数。

正确

错误

在编写异常处理的Java程序中,每个catch语句块都应该与( )语句块对应,使得用该语句块来启动Java的异常处理机制.

A、

if – else

B、

switch

C、

try

D、

throw

事件源不能自己监听自己产生的事件.

正确

错误

声明为final的方法不能被重写。( )

正确

错误

Java中的消息包括消息的接收者,接受者所用方法,方法所需参数三个部分.( )

正确

错误

Default子句只能出现在case子句后.

正确

错误

复合语句虽然由多条语句构成,但从功能上可视为一条语句,是一个整体。()

正确

错误

保留字 this 代表当前对象.( )

正确

错误

如果定义一个线程类,它继承自Thread,则我们必须重写其中的( )方法

A、

run

B、

start

C、

yield

D、

stop

Java中”+”运算符除可执行加法运算外也可用于字符串的连接操作。

正确

错误

静态变量使用前必须初始化。( )

正确

错误

Java的编译环境和运行环境必须在同一台机器上.()

正确

错误

Java 支持多线程机制。

正确

错误

进行AWT绘制时,需要程序员重写repaint()方法。

正确

错误

组件必须放置在一定的容器中才能显示.( )

正确

错误

创建对象时系统将调用适当的构造方法给对象初始化。

正确

错误

类Connection完成对指定数据库的连接操作.( )

正确

错误

一个 Java 源程序中允许有多个公共类。

正确

错误

线程一旦被创建就处于可运行状态.( )

正确

错误

程序中抛出异常时(throw …),只能抛出自己定义的异常对象。

正确

错误

数据报通信协议(UDP)是一种面向连接的协议.

正确

错误

JDBC API是一组抽象接口,可以通过它实现应用程序与数据库的连接.( )

正确

错误

数组成员只能为简单数据类型。

正确

错误

重载的方法可以通过它们返回值的不同类型来区分。( )

正确

错误

一个布局容器中可以混合使用多种布局策略。

正确

错误

Java字节码文件是与具体平台相关的。( )

正确

错误

Java在定义一个类的同时将为该类分配内存空间.

正确

错误

抽象类中至少要包含一个抽象方法。

正确

错误

main方法中不能声明抛弃异常。

正确

错误

不同包中的类的名字可以相同。

正确

错误

While结构与do..while结构是完全等价的两种结构.( )

正确

错误

类的私有属性和私有方法可以被其子类对象访问。

正确

错误

Java 源程序的文件名必须和公共类的类名相同.

正确

错误

socket类在java.lang中.( )

正确

错误

通过类FileOutputStream可以实现对文件的随机处理.

正确

错误

for 语句中的循环体不能是空的.( )

正确

错误

一个接口中只需进行方法的声明,而不提供具体的实现。

正确

错误

由于String定义的对象长度不能改变,所以不能对其执行连接操作.

正确

错误

线程与进程实际是同一个概念.( )

正确

错误

子类的对象能直接向其父类对象赋值.( )

正确

错误

要想从Internet上获得某个资源,首先要把这个资源的地址用URL类对象表示出来. ()

正确

错误

float与Float的使用完全一样,只是大小写的区别.()

正确

错误

Java中被申明为final的常量值是不允许被修改的.

正确

错误

构造函数能继承,也能被重载.( )

正确

错误

创建一个名为 MyPackage 的包的语句是import MyPackage。()

正确

错误

weinxin
微信咨询
这是我的微信扫一扫

发表留言

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: