C#笔试题目

一、 单选题

1 试图编译下面的代码块,将会出现什么结果? a

public class Test {

static int x;

public static void main(String args[]){

System.out.println("Value is " + x);

}

}

A"Value is 0"被打印输出。

B.一个异常NullPointerException被抛出。

C.产生"illegal array declaration syntax"的编译错误。

D.产生"possible reference before assignment"的编译错误。

2 在一个Frame中有一个按钮,使用什么样的布局管理器使得改变Frame的宽度时

候,只对按钮的宽度有影响而对按钮高度没有影响? (d)

A. FlowLayout                       B. GridLayout

C. Center area of a BorderLayout         D. North or South of a BorderLayout

3 java语言在语言的类型上应属于那种类型的语言 (b)

A 编译型的语言        B 解释型的语言

C 脚本型的解释语言    D 编译链接型的语言

4 下面属于电子商务产生的条件的是哪个? (d)

A 计算机的广泛应用,网络的普及和成熟

B 信用卡的普及和应用,电子交易安全协议的确定

C 政府的支持与推动      D、以上都是

5 电子商务有许多分类,其中 B to C 是指( ) (b)

A、企业与企业 B、企业与消费者 C、消费者与消费者 D、企业与政府

6 按照使用网络类型分类,以下不属于当前电子商务的主要形式是(d)。

AEDI商务 BInternet商务 CIntranet商务 DWWW商务

7 下面的技术中,哪一个是客户端脚本语言? (d)

A. ASP B. PHP C. Perl D. VBScript

8 IBM 电子商务应用框架中,以下哪个是客户端技术? (c)

A. Servlet B. JSP C. HTML D. EJB

9 HTML文件中可以嵌入JSP表达式。下面哪一个表明了正确的嵌入方式? (b)

A. <! 表达式内容 >            B. <%= 表达式内容 %>

C. <JSP:表达式内容>           D. <@ 表达式内容 @>

10 有一个电子商务应用,它需要使两个公司间的信息进行交互。这两个公司的数

据分别存放在DB2数据库中和Lotus 中。在IBM电子商务框架中,会推荐使用下

面哪一种标准来展现数据?- (d)

A. EDI B. IIOP C. HTML D. XML

11 下面那种技术可以与基于浏览器的WEB应用共同协作,使得某些错误能够直

接在终端用户的客户端处理而无需在WEB服务器端处理? (d)

A. XML B. CGI C. SGML D. JavaScript

12 作为电子商务解决方案的一部分,客户需要使用自己定义的标记集来标记数

据。下面哪一种技术是基于SGML的,并能满足客户的这一需求? (a)

A XML B. HTML C. DHTML D. JavaScript

13 下面那种语言是解释执行的(c )。

A. C++ B. Delphi C. JavaScript D. Java

14 一个标准的HTML文件是以<html>标记开始,并以哪一个标记结束? (d)

A. <html> B. </htm> C. <htm> D. </html>

15 下面哪些标签不会出现在文件头中? (c)

A. <TITLE….</TITLE>               B. <HEAD>…..</HEAD>

C. <CENTER>….</CENTER>         D. <META>

16 下面那个标签不是HTML中表格使用的标签? (c)

A. Tr.../Tr           B. Td.../Td

C. T.../T             D. Table.../Table

17 VBScript可以使html文件达到互动效果,VBScript是由哪个公司开发的。 (a)

A. Microsoft B. Netscape C. Sun D. IBM

18 html文件中,有两种方法设置宽度,第一种是以绝对方式设置表格宽度,

单位是(),第二种是以相对方式设置宽度,单位是()? (b)

A. 百分比,dot      B. pixel,百分比    C. 百分比,pixel    D. dot,百分比

19 给出下面的代码: (d)

if (x>0) { System.out.println("first"); }

else if (x>-3) { System.out.println("second"); }

else { System.out.println("third"); }

x在什么范围内,会输出:second

A. x > 0      B. x > -3     C. x <= -3     D. x <= 0 && x > -3

20 使用哪一个布局管理器时,当Frame的大小被改变时Frame中的按钮的位置

可能会被改变? (b)

A. BorderLayout     B. FlowLayout     C. CardLayout     D. GridLayout

21 下面哪一个说法可以使X线程变成可以运行的? (b)

A. 线程X被中断。

B. 线程Z释放在A对象上的线程锁,并调用A对象的notifyAll()方法。

C. 线程X的等待超时被中断。

D. 线程Z 调用Thread.sleep(100)方法。

22 下列哪一个语句是正确的? (b)

A. 为了调用wait()方法,一个线程必须拥有当前线程锁。

B. 为了调用wait()方法,一个线程必须拥有被调用对象的线程锁。

C. 为了调用join()方法,一个线程必须拥有被调用对象的线程锁。

D. 为了调用sleep ()方法,一个线程必须拥有被调用对象的线程锁。

23 下面哪些行代码在编译时不会出警告或错误信息? (d)

A. float f = 1.3;      B. char c = “a”;      C.byte b = 257;      D.Boolean b = null;

E .Int I = 10;

24 byte的取值范围是: (a)

A. -128 to 127     B. -256 to 256      C. -255 to 256    D. depends on the java Virtual machine

25 下列语句的输出应该是? (c)

int x=4;

System.out.println("value is "+ ((x>4) ? 99.9 :9));

A. 输出结果为:value is 99.9          B. 输出结果为:value is 9

C. 输出结果为:value is 9.0           D. 语句错误

26 关于java的面向对象的编程特性中的封装机制,以下说法正确的是? (a)

A. 将问题的特征属性与问题的功能方法相组合在一起形成一个类。

B. 将问题的特征属性与问题的功能方法相分离,形成各自的程序。

C. 将问题的特征属性内嵌到问题的功能方法的定义体中。

D. 对具体问题只需给出其功能实现方法,而不必给出其特征属性的定义。

27 下面的程序用如下的命令行java myprog good morning执行,结果是: (d)

public class myprog{

public static void main(String argv[]){

System.out.println(argv[2])

}

}

A. myprog

B. good

C. morning

D. Exception raised:”java.lang.ArrayIndexOutOfBoundsException:2”

28 MyClass声明如下:

class MyClass extends Object {

private int x;

private int y;

public MyClass() {

x = 0;

y = 0;

}

public MyClass(int x, int y) {

// .........

}

public void show() {

System.out.println("/nx=" + x + "y=" + y);

}

public void show(boolean flag) {

if (flag)

System.out.println("/nx=" + x + "y=" + y);

else

System.out.println("/ny=" + y + "x=" + x);

}

protected void finalize() throws Throwable {

super.finalize();

}

}

public static void main(String args[])方法体如下:

 

{

MyClass myclass=new MyClass(5,10);

myclass.show(false);

}

编译运行该程序将会有何结果?(c)

A.x=0y=0            B.x=5y=10         C.y=10x=5         D.y=0x=0

29 MyClass声明如下:

class MyClass extends Object {

private int x;

private int y;

public MyClass() {

x = 0;

y = 0;

}

public MyClass(int x, int y) {

// .........

}

public void show() {

System.out.println("/nx=" + x + "y=" + y);

}

public void show(boolean flag) {

if (flag)

System.out.println("/nx=" + x + "y=" + y);

else

System.out.println("/ny=" + y + "x=" + x);

}

protected void finalize() throws Throwable {

super.finalize();

}

}

public static void main(String args[])方法体如下:

{

MyClass myclass=new MyClass(5,10);

myclass.show(false);

}

现在想在main方法中加上一条语句来释放myclass对象,应用下面哪条? (a)

A.myclass=null;       B.free(myclass);       C.delete(myclass);    D.Java语言中不存在相应语句

30 Intranet一般称之为( d)。

A、外联网 B 广域网 C、局域网 D、企业内部网

31 在一个由客户端,协议防火墙、中间层(DMZ)、域防火墙及企业内部网构成

的电子商务系统中,一般情况下,协议防火墙会允许哪个/些协议通过? (c)

A. IIOP B. FTP C. HTTP/HTTPS D. JAVA

32 下面哪一个关于IBM电子商务应用框架的阐述是正确的? (d)

A. 它是一种开放的、不安全的体系结构,       B. 系统的当机时间不会影响雇员的生产率

C. 该框架中的后台数据库只支持DB2           D. 它是基于工业标准的,能够提供好的灵活性和可扩展性

33 一个电子商务解决方案由客户端、协议防火墙、应用服务器、域防火墙和企业

内部网几部分共同组成。企业认为这种解决方案比较昂贵。为了节省花费,企业管

理者希望能够除去第二层防火墙(即域防火墙)。在需求分析阶段,企业相关人员

指出安全性是非常重要的。 在这种需求下,第二层防火墙需要删除么? (b)

A. 不能删除。需要第二层防火墙保障安全性。防火墙必须成对安装以保证它的功能。

B. 不能删除。使用第二层防火墙可以改善安全。第二层防火墙能够防止外部INTERNET用户直接访问企业内部服务器。

C. 可以删除。使用两层防火墙可以增加整个系统的吞吐量,尽管如此,但是一层防火墙就足够了。

D. 可以删除。使用两层防火墙可以实现高可用性,尽管如此,但是一层防火墙就足够了。

34 如果你试图编译并运行下面的代码将发生什么? (c)

public class test {

public static void main(String argv[]) {

int anar[] = new int[5];

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

}

}

A. 有错误anar引用之前必须被初始化。         B. null        C. 0          D. 5

35 如果你试图编译并运行下面的代码将发生什么? (c)

abstract class MineBase {

abstract void amethod();

static int i;

}

public class Mine extends MineBase {

public static void main(String argv[]) {

int[] ar = new int[5];

for (i = 0; i < ar.length; i++)

System.out.println(ar[i]);

}

}

A. 一个0-5的序列将被打印。              B. 有错误ar使用之前将被初始化。

C. 有错误Mine 必须声明成abstract的。     D. IndexOutOfBoundes 错误。

36 如果你试图编译并运行下面的代码将发生什么? (c)

public class test {

public static void main(String argv[]) {

int i = 1;

switch (i) {

case 0:

System.out.println("zero");

break;

case 1:

System.out.println("one");

case 2:

System.out.println("two");

default:

System.out.println("default");

}

}

}

A. one     B. one, default    C. one, two, default       D. default

37 下面哪一个说明是正确的? (a)

A. 一个方法不能够覆盖成private的。       B. 静态方法不能够被覆盖。

C. private方法不能够被覆盖。      D. 一个覆盖的方法不能够抛出基类中非checked异常(Runtime Exception)。

38 下列那个是char类型的值的范围? (b)

A. -27~27-1         B. 0~216-1         C. 0~216        D. 0~28     

39 以下选项中循环结构合法的是? (c)

A. while (int i<7)

{ i++;

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

}

B. int j=3;

while(j)

{ System.out.println(" j is "+j);

}

C. int j=0;

for(int k=0; j + k !=10; j++,k++){

System.out.println(" j is "+ j + "k is"+ k);

}

D. int j=0;

do{

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

if (j = = 3) {continue loop;}

}while (j<10);

40 下面哪些是短整型short的取值范围: (c)

A-27 ——27-1              B0 ——215

C.–215 —— 215-1          D.–231 ——231-1

二、 多选题

1 执行下列代码后,哪个结论是正确的 String[] s=new String[10]; (bd)

A s[10] ""; B s[9] null;

C s[0] 未定义 D s.length 10

2 下面的表达式哪个是正确的? (ae)

A String s="你好";int i=3; s+=i;

B String s="你好";int i=3; if(i==s){ s+=i};

C String s="你好";int i=3; s=i+s;

D String s="你好";int i=3; s=i+;

E String s=null; int i=(s!=null)&&(s.length>0)?s.length():0;

3 关于float类型下面哪三个是正确的? (adf)

A. float foo=-1;           B. float foo=1.0;          C. float foo=42e1;       

D. float foo=2.02f;         E. float foo=3.03d;        F. float foo=0x0123;

4 关于下面的代码片段,请选择正确的ConstOver构造方法的重载方法?(ac)

public class ConstOver{

public ConstOver(int x, int y, int z){}

}

A.ConstOver(){}

B.protected int ConstOver(){} //not overload ,but no a error

C.private ConstOver(int z, int y, byte x){}

D.public void ConstOver(byte x, byte y, byte z){}

E.public Object ConstOver(int x, int y, int z){}

5 关于下面的代码片段,请选择正确的setVar的覆盖方法? (acd)

public class MethodOver{

public void setVar(int a, int b, float c){}

}

A.private void setVar(int a, float c, int b){}

B.protected void setVar(int a, int b, float c){}

C.public int setVar(int a, float c, int b){return a;}

D.public int setVar(int a, float c){return a;}

6 下面的选择项目中哪个成功地创建了Vector的一个实例,并且添加了一个元素? (bcd)

A. Vector v=new Vector(99);

v[1]=99;

B. Vector v=new Vector();

v.addElement(99);

C. Vector v=new Vector();

v.add(99);

D. Vector v=new Vector(100);

v.addElement("99");

7 使用File类你能够完成下面的哪些任务? (cd)

A. 改变当前文件夹。        B. 返回父文件夹的名字。

C. 删除文件。              D. 查询是否一个文件中包含文件信息还是二进制信息。

8 下面正确的创建Socket的语句有 (bc)

A Socket a = new Socket(80);

B Socket b = new Socket("130.3.4.5",80);

C ServerSocket c = new Socket(80)

D ServerSocket d = new Socket("130.3.4.5",80)

9 下面关于阻塞方法的论述,正确的有? (cd)

A 阻塞方法是指无法返回的方法

B 阻塞方法是指网络过于繁忙,方法必须等待

C 阻塞方法是指有外部事件发生才会返回的方法。

D 阻塞方法如果不能马上返回,就会进入等待状态,把系统资源让给其他线程

10 下面正确的论述有? (abc)

A ServerSocket.accept是阻塞的            B BufferedReader.readLine是阻塞的

C DatagramSocket.receive是阻塞的         D DatagramSocket.send是阻塞的

11 给定下列代码: (bc)

public class Parent {

public int addValue( int a, int b) {

int s;

s = a+b;

return s;

}

class Child extends Parent {

}

下列哪些方法可以作为Child类的方法?

A. int addValue( int a, int b ){// do something...}       B. public void addValue (){// do something...}

C. public int addValue( int a ){// do something...}

D. public int addValue( int a, int b )throws MyException {//do something...}

12 下面的哪些程序片断可能导致错误? (bd)

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";

13 下列哪些接口在Java中没有定义相对应的Adapter类? (cd)

A. MouseListener     B. KeyListener     C. ActionListener     D. ItemListener     E. WindowListener

14 那些类可以用来实现TCP/IP客户服务器程序? (ac)

A. ServerSocket     B. Server     C. Socket     D. DatagramPacket     E. DatagramSocket

15 下面哪两个是等价的? (cd)

A. 3/2      B. 3<2     C. 3*4     D. 3<<2      E. 3*2^2     F. 3<<<2

16 下面的表达式哪个是正确的? (ae)

A String s="你好";int i=3; s+=i;

B String s="你好";int i=3; if(i==s){ s+=i};

C String s="你好";int i=3; s=i+s;

D String s="你好";int i=3; s=i+;

E String s=null; int i=(s!=null)&&(s.length>0)?s.length():0;

17 选出合理的标识符 (ac)

A _sys1_lll     B 2mail    C $change     D class

18 哪个布局管理器使用的是组件的最佳尺寸( preferred size (ae)

A FlowLayout    B BorderLayout   C GridLayout   D CardLayout    E GridBagLayout

19 下列哪个方法可用于创建一个可运行的类? (ae)

A public class X implements Runable{ public void run(){ ......} }

B public class X implements Thread{ public void run(){ ......} }

C public class X implements Thread{ public int run(){ ......} }

D public class X implements Runable{ protected void run(){ ......} }

E public class X extends Thread{ public void run(){ ......} }

20 下面哪个方法可以在任何时候被任何线程调用? (def)

A notify()     B wait()     C notifyAll()    D sleep()    E yield()    F synchronized(this)

21 构造BufferedInputStream的合适参数是哪个? (ac)

A BufferedInputStream     B BufferedOutputStream

C FileInputStream         D FileOuterStream            E File

22 下列说法正确的是 (bc)

A java.lang.Clonable是类          B java.lang.Runnable是接口

C Double对象在java.lang包中    D Double a=1.0是正确的java语句

23 指出正确的表达式 (ab)

A double a=1.0;      B Double a=new Double(1.0);    C byte a = 340;     D Byte a = 120;

24 定义一个类名为"MyClass.java"的类,并且该类可被一个工程中的所有类访

问,那么该类的正确声明应为: (cd)

A private class MyClass extends Object     B class MyClass extends Object

C public class MyClass                  D public class MyClass extends Object

25 下面的代码将输出什么结果? (ab)

public class MyFor {

public static void main(String argv[]) {

int i;

int j;

outer: for (i = 1; i < 3; i++)

inner: for (j = 1; j < 3; j++) {

if (j == 2)

continue outer;

System.out.println("Value for i=" + i + " Value for j=" + j);

}

}

}

A. Value for i=1 Value for j=1       B. Value for i=2 Value for j=1

C. Value for i=2 Value for j=2       D. Value for i=3 Value for j=1

26 在下面注释//Method Here部分可以插入什么代码 ? (bc)

class Base {

public void amethod(int i) {

}

}

public class Scope extends Base {

public static void main(String argv[]) {

}

// Method Here

}

A. void amethod(int i) throws Exception {}     B. void amethod(long i)throws Exception {}

C. void amethod(long i){}                   D. public void amethod(int i) throws Exception {}

27 分析下面代码在XX的注释部分哪些修饰符是有效的? (abc)

public class MyClass1 {

public static void main(String argv[]) {

}

/* Modifier at XX */ class MyInner {

}

}

A. public         B. private         C. static       D. friend

28 指出下列哪个方法与方法public void add(int a){}为合理的重载方法。(cd)

A public int add(int a)            B public void add(long a)

C public void add(int a,int b)      D public void add(float a)

29 如果下列的方法能够正常运行,在控制台上将显示什么? (acd)

public void example(){

try{

unsafe();

System.out.println("Test1");

} catch(SafeException e) {

System.out.println("Test 2");

}finally{System.out.println("Test 3");}

System.out.println("Test 4");

}

A Test 1      B Test 2     C Test 3      D Test 4

30 下列哪些是JAVA的修饰符? (abd)

A public     B private    C friendly    D transient     E vagrant

31 下面哪些语句是正确的? (bde)

A 如果多个监听器注册到一个组件只有最新一个监听器监听的事件会执行

B 如果多个监听器注册到一个组件所有的事件保证不分先后都会执行

C 注册多个监听器到一个组件会引起编译错误

D 你可以添加或删除多个监听器到一个组件

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

32 下面哪些选项将是下述程序的输出? (abc)

public class Outer{

public static void main(String args[]){

Outer: for(int i=0; i<3; i++)

inner:for(int j=0;j<3;j++){

if(j>1) break;

System.out.println(j+"and"+i);

}

}

}

A 0 and 0     B 0 and 1     C 0 and 2    D 0 and 3    E 2 and 2    F 2 and 1

G 2 and 0

33 下面哪些语句能够正确地生成5个空字符串? (ab)

A String a[]=new String[5]; for(int i=0;i<5;a[++]="");

B String a[]={"","","","",""};

C String a[5];

D String[5]a;

E String []a=new String[5]; for( int i=0;i<5;a[i++]=null);

34 下面哪个代码段不会出现编译错误? (bc)

A import java.awt.*;

package Mypackage;

class Myclass {}

B package MyPackage;

import java.awt.*;

class MyClass{}

C /*This is a comment */

package MyPackage;

import java.awt.*;

class MyClass{}

35 下面的语句创建一DatagramSocket对象,哪些是正确的? (abc)

A DatagramSocket a = new DatagramSocket()

B DatagramSocket b = new DatagramSocket(80)

C DatagramSocket c = new DatagramSocket("127.0.0.1",70)

D DatagramSocket d = new DatagramSocket("127.0.0.1")

36 关于数据报通信(UDP)和流式通信(TCP)的论述,正确的有? (cd)

A .TCPUDP在很大程度上是一样的,由于历史的原因产生了两个不同的名字而已

B. TCPUDP在传输方式上是一样的,都是基于流的,但是TCP可靠,UDP不可靠

C .TCPUDP使用的都是IP层所提供的服务

D. 用户可以使用UDP来实现TCP的功能

37 下面标识符那些是JAVA中的保留字或关键字 (acde)

A if B then

C goto D while

E case

38 下面代码段编译不会出现错误的是? (bc)

A int i=0;

if(i) {

System.out.println("Hello");

}

B boolean b=true;

boolean b2=true;

if(b==b2) {

System.out.println("So true");

}

C int i=1;

int j=2;

if(i==1||j==2)

System.out.println("OK");

D int i=1;

int j=2;

if(i==1 &| j==2)

System.out.println("OK");

39 下面那个句子是正确是 (abc)

A System.out.println( -1 >>> 2);将输出一个大于10大数

B System.out.println( -1 >>> 2);将输出一个正数

C System.out.println( 2 >> 1);将输出1

D System.out.println( 1 <<< 2); will output the number 4

40 下面代码输出的结果是? (ab)

public class MyFor{

public static void main(String argv[]){

int i;

int j;

outer:for (i=1;i <3;i++)

inner: for(j=1; j<3; j++) {

if (j==2)

continue outer;

System.out.println("Value for i=" + i + " Value for j=" +j);

}

}

}

A Value for i=1 value for j=1

B Value for i=2 value for j=1

C Value for i=2 value for j=2

D Value for i=3 value for j=1

三、 程序解析题

1 运行下面程序,会得到什么结果 (b)

String s=new String("Bicycle");

int iBegin=1;

char iEnd=3;

System.out.println(s.substring(iBegin,iEnd));

A Bic B ic

C icy D error: 没有匹配的方法substring(int,char)

2 给出下面的代码块,请选择正确的选项? (b)

public class FooBar {

public static void main(String[] args) {

int i = 0, j = 5;

tp: for (;; i++) {

for (;; --j)

if (i > j)

break tp;

}

System.out.println("i=" + i + ",j=" + j);

}

}

A.i=1,j=-1 B. i=0,j=-1 C.i=1,j=4 D.i=0,j=4

3 给出下面的代码块,

String foo = "blue";

boolean[] bar = new boolean[1];

if (bar[0]) {

foo = "green";

}

变量foo的值是什么? (c)

A."" B.null C.blue D.green

4 编译下面代码段,会出现什么结果 (c)

Integer ten=new Integer(10);

Long nine=new Long (9);

System.out.println(ten + nine);

int i=1;

System.out.println(i + ten);

A 先输出19后输出20

B 先输出19后输出11

C Error: 不能转换类型

D 先输出10后输出1

5 运行下列程序, 会产生什么结果 (a)

public class X extends Thread implements Runable{

public void run(){

System.out.println("this is run()");

}

public static void main(String args[]){

Thread t=new Thread(new X());

t.start();

}

}

A 第一行会产生编译错误

B 第六行会产生编译错误

C 第六行会产生运行错误

D 程序会运行和启动

6 指出下列程序运行的结果 (b)

public class Example{

String str=new String("good");

char[]ch={'a','b','c'};

public static void main(String args[]){

Example ex=new Example();

ex.change(ex.str,ex.ch);

System.out.print(ex.str+" and ");

Sytem.out.print(ex.ch);

}

public void change(String str,char ch[]){

str="test ok";

ch[0]='g';

}

}

A good and abc B good and gbc

C test ok and abc D test ok and gbc

7 编译如下代码可能出现的结果是 (c)

public class Holt extends Thread{

private String sThreadName;

public static void main(String argv[]){

Holt h = new Holt();

h.go();

}

Holt(){}

Holt(String s){

sThreadName = s;

}

public String getThreadName(){

return sThreadName;

}

public void go(){

Holt first = new Holt("first");

first.start();

Holt second = new Holt("second");

second.start();

}

public void start(){

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

System.out.println(getThreadName() +i);

try{

Thread.sleep(100);

}catch(InterruptedExceptione){

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

}

}

}

}

A 编译时出错

B 输出 first0, second0, first0, second1

C 输出 first0, first1, second0, second1

D 运行时出错

8 给出下面的代码块,请选择正确的输出结果? d

int i = 1, j = 10;

do {

if (i++ > --j) {

continue;

}

} while (i < 5);

System.out.println("i = " + i + "and j = " + j);

A. i = 6 and j = 5

B. i = 5 and j = 5

C. i = 6 and j = 5

D. i = 5 and j = 6

9 当你试图编译运行如下代码时会出现什么结果 (c)

class Background implements Runnable{

int i=0;

public int run(){

while(true){

i++;

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

} //End while

return 1;

}//End run

}//End class

A 编译通过执行run方法会输出i递增值

B 编译通过当调用开始输出i递增值

C 在编译时代码引起错误.

D 由于没有正确的参数编译时出错.

10 编译下面代码会出现什么结果 (d)

public class Conv{

public static void main(String argv[]){

Conv c=new Conv();

String s=new String("ello");

c.amethod(s);

}

public void amethod(String s){

char c='H';

c+=s;

System.out.println(c);

}

}

A 编译通过并输出字符串"Hello"

B 编译通过并输出字符串"ello"

C 编译通过并输出字符串"elloH"

D 编译出错

四、 程序填空题

1 给出下面的代码块,变量foo的值是_______?

public class X {

public static void main(String[] args) {

String foo = "ABCDE";

foo.substring(3);

foo.concat("XYZ");

}

}

答案: ABCDE

2 执行下列程序段的结果是:_________________

public class Example{

public static void main(String argc[]){

int x,a=2,b=3,c=4;

x=++a+b+++c++;

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

System.out.println(“a=”+a);

System.out.println(“b=”+b);

System.out.println(“c=”+c);

}

}

答案是:

x=10

a=3

b=4

c=5

3 在下面代码的_______填写适当代码,使程序可以正确运行。

public class EqTest {

public static void main(String argv[]) {

EqTest e = new EqTest();

}

EqTest() {

String s = "Java";

String s2 = "java";

_________ {

System.out.println("Equal");

}

else {

System.out.println("Not equal");

}

}

}

答案: if (s.equalsIgnoreCase(s2))

4 下列程序段执行的结果是:

import java.io.* ;

public class abc

{

public static void main(String args[ ])

{ int i , s = 0 ;

int a[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 };

for ( i = 0 ; i < a.length ; i ++ )

if ( a[i]%3 = = 0 ) s += a[i] ;

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

}

}

答案:s=180

5 下列程序中构造了一个SET并且调用其方法add(),输出结果是_________

import java.util.*;

public class Example{

public int hashCode(){

return 1;

}

public boolean equals(Object b){

return true;

}

public static void main(String args[]){

Set set=new HashSet();

set.add(new Example());

set.add(new Example());

set.add(new Example());

System.out.println(set.size());

}

}

答案:1

6 下列程序的运行结果是_____________

class Example{

class Dog{

private String name;

private int age;

public int step;

Dog(String s,int a){

name=s;

age=a;

step=0;

}

public void run(Dog fast){

 

fast.step++;

}

}

public static void main (String args[]){

Example a=new Example();

Dog d=a.new Dog("Tom",3);

d.step=25;

d.run(d);

System.out.println(d.step);

}

}

答案:26

7 请在下面程序运行结果是__________

public class Test {

private static int j = 0;

public static boolean methodB(int k) {

j += k;

return true;

}

public static void methodA(int i) {

boolean b;

b = i > 10 & methodB(1);

b = i > 10 && methodB(2);

}

public static void main(String args) {

methodA(0);

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

}

}

答案: j = 1

8 下面语句段的输出结果是什么? _____________

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");

}

答案:default, zero

9 给出程序片段,空格处应该添入什么句子设置框架背景颜色为pink

import java.awt.*;

public class SetF extends Frame{

public static void main(String argv[]){

 

SetF s=new SetF();

s.setSize(300,200);

s.setVisible(true);

______________

}

}

答案:s.setBackground(Color.pink);

10 执行下面程序,将输出什么结果______________

public class Pass{

static int j=20;

public static void main(String argv[]){

int i=10;

Pass p = new Pass();

p.amethod(i);

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

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

}

public void amethod(int x){

x=x*2;

j=j*2;

}

}

答案:i=10    j=40

五、 编程题:(1道)

1. 编写程序计算结果:有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。

问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2

个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?

答案:18

参考程序如下:

public class Example{

public static int age(int n){

int c;

if(n==1)

c=10;

else

c=age(n-1)+2;

return c;

}

public static void main(String args[]){

int x=age(5);

System.out.println("5个人岁数是:"+x);

}

}

1 编写程序计算下列问题:有一分数序列:2/13/25/38/513/821/13...求出这个

数列的前20项之和。

答案:31.042229

参考程序如下:

public class Example

{

public static void main(String[] args)

{

int a=2,b=1,t,number=20;

float s=0;

for(int n=1;n<=number;n++){

s=s+(float)a/b;

t=a;a=a+b;b=t;

}

System.out.println("sum is "+s);

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值