《JAVA语言程序设计》期末考试复习资料(2)

2019-03-11 11:20

int k = i;

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

if ( a[j]

}

for ( i =0 ; i

System.out.print(a[i]+\ \

System.out.println( ); } }

3.写出以下程序的功能。

import java.io.*; public class TestFile {

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

BufferedReader br = new BufferedReader(

new InputStreamReader(System.in));

BufferedWriter bw = new BufferedWriter(new FileWriter(“input.txt\ String s; while (true)

{

System.out.print(\请输入一个字符串: \ System.out.flush(); s=br.readLine(); if (s.length()==0) break; bw.write(s); bw.newLine(); } bw.close(); }

}

功能:从键盘逐一输入字符串,逐一输出至input.txt文件中,直至输入空行。

4.阅读以下程序,写出输出结果。

class Animal { Animal() {

System.out.print (\ \ } }

public class Dog extends Animal { Dog() {

System.out.print (\ }

public static void main(String[] args) { Dog snoppy= new Dog(); } }

输出结果:Animal Dog

《JAVA语言程序设计》期末考试试题及答案3(应考

必备题库)

一、单项选择题

1、如下哪个是Java中的标识符( D )

A、public

4、如下哪个是Java中有效的关键字( C )

A、name

5、下面的代码段执行之后count的值是什么( D )

int count = 1;

for (int i = 1; i <= 5; i++) { }

System.out.println(count);

count += i;

B、super C、3number D、width

B、hello C、false D、good

A、5

B、1 C、15 D、16

6、定义一个类,必须使用的关键字是( B )

A、public

7、定义一个接口必须使用的关键字是( C )

A、public

B、class

C、interface

D、static

9、声明并创建一个按钮对象b,应该使用的语句是( A )

A、Button b=new Button(); B、button b=new button(); C、Button b=new b(); D、b.setLabel(“确定”);

10、Frame对象默认的布局管理器是( B )

A、FlowLayout C、CardLayout

11、以下程序段的输出结果是(三角形)

int x = 5, y = 6, z = 4;

if (x + y > z && x + z > y && z + y > x) System.out.println(\三角形\); else

System.out.println(\不是三角形\);

B、class C、interface D、static

B、BorderLayout D、null

12、下面程序段的执行结果是(6 5 4 3 2)

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

for (int i = a.length - 1; i >= 0; i--)

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

三、程序阅读题

1、以下程序的输出结果为_ Peter is 17 years old!___。

public class Person { }

public static void main(String[] args) { }

Person c = new Person(\, 17);

System.out.println(c.name + \ + c.age + \); public Person(String name, int age) { }

this.name = name; this.age = age; String name; int age;

2、以下程序的输出结果为__课程号:101 课程名:ASP 学分:3___。

public class Course {

public void printCourseInfo() {

System.out.println(\课程号:\ + cNumber + \课程名:\ + cName + \学public Course(String number, String name, int unit) { }

cNumber = number; cName = name; cUnit = unit; private String cNumber; private String cName; private int cUnit;

分:\ + cUnit); } }

class CourseTest {

}

public static void main(String[] args) { }

Course c;

c = new Course(\, \, 3); c.printCourseInfo();

3、以下程序的输出结果为__汤姆猫体重:20.0斤___。

public class Tom { }

public static void main(String[] args) { }

Tom.name = \汤姆猫\; Tom cat = new Tom(); cat.setWeight(20); cat.out(); private void out() {

System.out.println(name + \体重:\ + weight + \斤\); }

public void setWeight(float weight) { }

this.weight = weight; private float weight; private static String name;

4、以下程序的输出结果_姓名:Tom 年龄:15 家庭住址:金水区 电话:66123456 学校:九中_。

public class Father {

void out() {

System.out.print(\姓名:\ + name); System.out.print(\年龄:\ + age); public Father(String name, int age) { }

this.name = name; this.age = age;

String name, address, tel; int age;


《JAVA语言程序设计》期末考试复习资料(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:浅谈房地产企业全面预算管理中存在的问题及对策

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: