导航:首页 > 编程语言 > java测试填空的文档

java测试填空的文档

发布时间:2023-06-27 20:35:41

1. 求大量java习题!!!急!!!(不是编程题)

注意:还不是完整的文档,太长了不能全帖完。要的话找我!^_^
《Java程序设计》练习题
一、判断题
1、 Java语言采用面向对象的思想编程,具有跨平台、分布式、多线程等优点。 ( )
2、 一个Java源程序可有多个类,但只仅有一个public类,而且程序名与public类名相同。 ( )
3、方法中的形参可以和方法所属类的属性同名。 ( )
4、接口无构造器,不能有实例,也不能定义常量。 ( )
5、利用File对象可以判断一个文件或目录是否存在。 ( )
6、JFrame,JPanel,JApplet和JButton四种组件都属于容器组件。 ( )
7、BorderLayout是面板的缺省布局管理器。 ( )
8、BorderLayout最多可以使用5个组件。 ( )
9、一个面板(JPanel)不能被加入另一个面板(JPanel)中。 ( )
10、菜单需要一个JMenuBar对象,以使他们能被添加到JFrame。 ( )
11、线程可以用yield使同优先级的线程运行。 ( )
12、System.in是标准输入流,能用read方法读取键盘的输入。 ( )
13、数据流就是数据通信通道,指在计算机的输入输出之间运动的数据序列。( )

二、填空题
1、设x,y,z的值分别为ture、false和false,试计算下列逻辑表达式的值:
(1) x &&y||!z&&ture (2) !x||!y&&!z
(3) (!x&&!y)||(!y&&!z) (4) x&&y||true&&!z

2、求下面表达式的值:
(1) 已知x=2、y=6、z=5.0,求x+(int)y/2*z%4
(2) 已知x=123,求x/100+x%100/10+x%10
(3) 已知x=160、y=2.8、z=5,求(byte)x +(int)y+(float)z;
(4) 设 int x=17,y=5; 执行语句 x%=x++/--y 后x的值为 。
(5) 设 int a=7,b=6,c=5;,表达式 (a+b)>(c*c)&&b==c||c>b 的值为 。
(6) 设 int a=3,b=5,c=7;,表达式a>c||c>b!=0&&c==b+a 的值为 。

3、下列表达式中n和x被赋值为多少?
int n=0;
int x=1;
n=x++ + x++; //这里n= , x=
n=n++ - x--; //这里n= , x=
n=x-- + -x++; //这里n= , x=
n=++x + x++; //这里n= , x=

4、使用 方法为组件设置布局管理器,JFrame的缺省布局管理器是 ,内容面板的缺省布局管理器是 。
5、写出4个常见的异常例子: 、 、 和 。重新抛出一个异常用 语句。
6、线程通过 方法可以休眠一段时间,然后恢复运行,当 时,线程进入死亡状态。
7、编写一个线程可以用 和 来实现。
8、创建文件(c:\test.txt)对象的语句是 ,DataInputStream对象提供 方法可以按行读取文件内容。
9、Container 的________方法可以将_______组件加入容器。
10、在执行Java线程的程序中,程序通过调用_______方法启动线程,随后又调用________方法。
11、使用 方法为组件设置布局管理器,JFrame的缺省布局管理器是 ,内容面板的缺省布局管理器是 。
12、Java.swing.JFrame.getContentPane()的返回类型是 。
13、数据越界抛出的异常类是 ,整数除零抛出的异常类是 ,算术溢出抛出的异常类是 。

三、选择题
1、 下面哪些是不合法的变量名称? ( )
A) 2D B) True C) _name D) T1 E) while-ture
2、下列变量定义不正确的是: ( )
A) boolean status=false; B) float d = 45.6;
C) char c = “a”; D) int k = 1+’1’; E) float f=1/4;
3、下列数组的定义不合法的是: ( )
A) char c[][]=new char[2][3];
B) char c[][]=new char[6][];
C) char [][]c=new char[3][3];
D) char [][]c=new char[][4];
E) int []a[] = new int[10][10];
4、对于下列代码:
public class Example{
String str=new String("hello");
char ch[]={'d','b','c'};
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.println(ex.str+"and"+ex.ch[0]);
}
public void change(String str,char ch[]){
str="world";ch[0]= 'a';
}
}
输出结果是: ( )
A) hello and d B) hello and a
C) world and d D) world and a
5、下列说法哪个是正确的? ( )
A) 子类不能定义和父类同名同参数的方法
B) 子类只能继承父类的方法,而不能重载
C) 重载就是一个类中有多个同名但有不同形参和方法体的方法
D) 子类只能覆盖父类的方法,而不能重载
6、如果一个程序段中有多个catch,则程序会按如下哪种情况执行? ( )
A) 找到合适的例外类型后继续执行后面的catch
B) 找到每个符合条件的catch都执行一次
C) 找到合适的例外类型后就不再执行后面的catch
D) 对每个catch都执行一次
7、以下哪一项不是File类的功能: ( )
A) 创建文件
B) 创建目录
C) 删除文件
D) 拷贝文件
8、下列说法哪个是正确的? ( )
A) BorderLayout是面板的缺省布局管理器
B) 当鼠标指针位于一个GUI组件的边上时,发生一个MouseOver事件
C) 一个面板(Jpanel) 不能被加入到另一个面板(Jpanel)中
D) 在BorderLayout中,添加到NORTH区的两个按钮将并排显示。
9、在java程序中,下列关于线程的说法错误的是: ( )
A) run方法是运行线程的主体
B) 多个进程运行时执行顺序是按顺序执行的
C) 如果线程死亡,它便不能运行
D) 在java中,高优先级的可运行线程会抢占低优先级线程
10、关于JDBC访问数据库的说法错误的是: ( )
A) 建立数据库连接时,必须加载驱动程序,可采用Class.forName()实现
B) 用于建立与某个数据源的连接可采用DriverManager类的getConnection方法
C) 建立数据库连接时,必须要进行异常处理
D) JDBC中查询语句的执行方法必须采用Statement类实现
四、程序阅读题
1、阅读下面的程序,程序保存为Test.java:
1) public class Test
2) {
3) public static void main(String[] args)
4) {
5) System.out.println(args[2]);
6) }
7) }
以上程序经编译后用java Test 1 2 3 运行得到的输出结果是什么?

2、阅读下面的程序:
① public class Test{
② public static void main(String[] a){
③ int i = Integer.parseInt(a[0]);
④ switch (i) {
⑤ case 1:System.out.println("Frist season");break;
⑥ case 2:System.out.println("Second season");
⑦ case 3:System.out.println("3th season");break;
⑧ case 4:System.out.println("Last season");
⑨ }
⑩ }
⑪ }
上面的程序编译是否成功?如果编译出错,指出哪行出错,并说明理由;如果编译正确,用java Test 2 运行得到的输出结果是什么?

3、阅读下面的程序:
① public class Test{
② public static void main(String[ ] args) {
③ int x,y=2,i=0,j=0;
④ if(args.length<2) System.exit(-1);
⑤ x = Integer.parseInt(args[1]);
⑥ switch(x){
⑦ case 1:switch(y){
⑧ case 1:i++;break;
⑨ case 2:j++;break;
⑩ default:i++;j++;
⑪ }
⑫ case 2:i++;j++;break;
⑬ default:i++;j++;
⑭ }
⑮ System.out.println("i="+i);
⑯ System.out.println("j="+j);
⑰ }
⑱ }
上面的程序编译是否成功?如果编译出错,指出哪行出错,并说明理由;如果编译正确,用java Test 1 2 3 运行得到的运行结果是什么?

4、阅读下面的程序,程序保存为Test.java:
1) public class Test
2) {
3) short mValue;
4) public static void main(String[] args)
5) {
6) int a = 32;
7) int b = 56;
8) Test os = new Test(a+b);
9) os.Show( );
10) }
11) protected Test(short aValue) { mValue = aValue; }
12) public void Show( ) { System.out.println(mValue); }
13) }
上面的程序编译是否成功?如果编译出错,指出哪行出错,并说明理由;如果编译正确,运行结果是什么?

5、阅读下面的程序:
class test
{
public static void main(String[] args)
{
int i = 1;
int All = 0;
for (;i<=10;i++)
{
if (i%6==0) break;
if(i%2==0) {i=i+2;continue;}
All = All + i;
}
System.out.println(All);
}
}
上面的程序编译是否成功?如果编译出错,指出哪行出错,并说明理由;如果编译正确,运行结果是什么?

6、阅读下面的程序,程序保存为Test.java:
1) public class Test
2) {
3) public static void main(String[] args)
4) {
5) int i = 100;
6) int j = 0;
7) boolean b = true;
8) while (b)
9) {
10) if (b||(i<50)) b = false;
11) else b = true;
12) j=j+1;
13) i=i-1;
14) }
15) System.out.println(j);
16) }
17) }
上面的程序经编译,运行后输出的结果是什么?

7、阅读下面的程序:
1) public class test
2) {
3) public static void main(String argv[])
4) {
5) Bird b = new Bird();
6) b.Fly(3);
7) }
8) }
9) class Bird
10) {
11) static int Type = 2;
12) private void Fly(int an_Type)
13) {
14) Type = an_Type;
15) System.out.println("Flying..."+Type);
16) }
17) }
上面的程序编译是否成功?如果编译出错,指出哪行出错,并说明理由;如果编译正确,运行结果是什么?

8、阅读下面的程序:
1) abstract class Base{
2) abstract public void myfunc();
3) public void another(){
4) System.out.println("Another method");
5) }
6) }
7) public class Abs extends Base{
8) public static void main(String argv[]){
9) Base b = new Abs();
10) b.another();
11) }
12) public void myfunc(){
13) System.out.println("My Func");
14) }
15) public void another(){
16) myfunc();
17) }
18) }
以上程序经编译后,运行结果是什么?

9、阅读下面的程序:
1) class Super{
2) public int i=0;
3) public Super(){
4) i=1;
5) }
6) }
7) public class Sub extends Super{
8) public Sub(){
9) i=2;
10) }
11) public static void main(String args[]){
12) Sub s=new Sub();
13) System.out.println(s.i);
14) }
15) }
上面的程序经编译后,运行结果是什么?

10、阅读下面的程序,程序保存为Test.java:
1) public class Test {
2) public static void main(String[ ] args) {
3) int index=0;
4) while (index<=100) {
5) index+=10;
6) if (index==40)
7) break;
8) System.out.println("The index is "+index);
9) }
10) }
11) }
上面的程序经编译,运行后输出的结果是什么?

五、问答题
1、 设int类型变量x和y分别初始化为3和100,下列语句的循环体共执行几次?执行完下列语句后x和y的值分别是多少?
(1) while(x<=y) x=2*x;
(2) while(y/x>5) if(y-x>25) x=x+1; else y=y/x;
(3) do{x=2*x;} while(x<y);
(4) do{x=y/x;y=y-x;}while(x>=y);
(5) do{y=y/x-1; if(y>=x) y=x;} while(y>=1);

2、简述对象、类的概念。
3、简述封装、继承性和多态性的概念。
4、根据以下的设计要求编写java源代码。
类名: Circle
实例数据(均为private):
radius(double) //圆的半径
方法:
构造方法(没有参数,设置radius的值为10.0)
setRadius(有一个double参数,将radius的值设为这个新值),
getRadius (没有参数,返回radius的值)
sameSize(有一个参数,是另一个Circle对象的引用,如果两个Circle对象的radius的差小于0.001,则返回true)

5、下面的代码使用上题的Circle类,请回答下面的问题:
public class CircleTester {
public static void main(String[] args) {
Circle c1,c2,c3;
c1 = new Circle();
c2 = new Circle();
System.out.println(“are same is: “+c1.sameSize(c2));
c2.setRadius(20.0);
compare.reset();
System.out.println(“are same is: “+c1.sameSize(c2));
}
}
问题:
(1) 共创建了几个Circle对象?
(2) 程序运行的结果是什么?

6、假设已有一个ArrayMethods 类,包含以下的方法:
public static void replace(double[] a, int p, double v)
将数组a中下标为p的元素的值替换为v.
public static void fill(double[] a, int p, double v)
将数组a中的前p个元素用value值填充(即将数组a的前p个元素的值,设成v),如果数组的长度小于p,则全部元素都设成v
public static void display(double[] a)
屏幕上显示数组a的内容

现在假设你在main()方法中已经声明了如下变量:
double[] array1={4.5, 6.0, 0.1, 2.2};
double[] array2;
double num1;
int pos=3;
要求对下面的3组语句,先回答是否合法(即没有编译错误),如果是合法的,请描述程序运行的效果,如果不合法,请说明理由.
1) num1 = array1[2];
ArrayMethods.replace(array1, pos, num1);
ArrayMethods.display(array1);
2) num1 = array1[0];
ArrayMethods.fill(array1, pos, num1);
ArrayMethods.display(array1);
3) num1 = array1[1];
array2=new double[num1];
ArrayMethods.display(array2);

六、编程题
1、分别利用for、while、do~while编写计算正整数n1到n2的累加和。
2、编写一个编程,给定一个t的值(t的值也可通过命令行输入),按下式计算y值并输出,要求分别写作if语句和switch语句。
t2-1 0≤t<1
t3-2•t-2 1≤t<3
y= t2-t•sint 3≤t<5
t+1 5≤t<7
t-1 其它

3、设计一个类TestArraySum,定义一个含有10个元素的int类型数组a,10个数组元素的值是11~20,再定义一个方法arraySum(int[] a),返回数组所有元素的和,最后用main方法实现在屏幕上输出数组a所有元素的和。

4、编写一个java程序Suansu.java,定义两个整型变量a和b,使用构造函数初始化a为10,b为5,并定义求出a与b的和(方法名为AddAB)、差(方法名为SubAB)、积(方法名为MultiAB)、商 (方法名为DivAB)的方法。
用另一个java程序TestSuansu.java测试Suansu.java定义的方法,并在屏幕上输出结果。

5、创建一个名为Rectangle的类来表示一个使用宽度和高度来改变量的矩形,矩形的宽度和高度由构造方法来确定。为Rectangle类创建下列方法:
 getArea返回矩形的面积,要求长和高的范围为0~50;
 getPerimeter返回矩形的周长;
 Draw使用星号(*)作为描绘字符画出该矩形(假设宽度和高度为整数);
在另一个类TestRectangle中编写main方法来测试Rectangle类。
6、用面向对象的思想定义一个接口Area,其中包含一个计算面积的方法CalsulateArea(),然后设计MyCircle和MyRectangle两个类都实现这个接口中的方法CalsulateArea(),分别计算圆和矩形的面积,最后写出测试以上类和方法的程序。
7、创建一个Frame,有两个Button按钮和一个TextField,点击按钮,在TextField上显示Button信息。
8、创建下图的GUI程序(注意:不需要提供任何功能)。

9、编写一个文件拷贝的程序,将文件C:\test1.txt的内容拷贝到C:\test2.txt中。
10、编写一个程序,统计给定文件中每个字母出现的频率。
11、编写一个程序,统计给定文件中包含的单词数目,并按单词表的顺序显示统计结果。
12、用图形界面设计一个简单的计算器。
13、用图形界面实现简单的银行柜台业务,包含创建新帐户、取款、存款、查询帐户余额等业务。

2. Java测试题

/**
* Student类
* @author hsf
* 没有实质的改动,把有关结果判断的方法放到Course类中,
* 在Student类中new Course的对象调用它的方法,功能是一样的。
*/
public class Student {

public static void main(String[] args) {
System.out.println("Welcome to the student course admin");

Course sc = new Course();
System.out.println("Collecting information for subject 0");
sc.evaluatue();

System.out.println("Collecting information for subject 1");
sc.evaluatue();

System.out.println("Collecting information for subject 2");
sc.evaluatue();
}

}

import java.util.Scanner;

/**
* Course类
*
* @author hsf
*/
public class Course {
int num1, num2;

public void evaluatue() {
Scanner sn = new Scanner(System.in);
Course st = new Course();

System.out.println("Enter mark out of 50 for Assessment task 0:");
num1 = sn.nextInt();
st.check(num1);

System.out.println("Enter mark out of 50 for Assessment task 1:");
num2 = sn.nextInt();
st.check(num2);

int sum = num1 + num2;
if (sum < 100 && sum >= 80) {
System.out.println("Subject Mark:" + sum + "-HD");
} else if (sum >= 70 && sum < 79) {
System.out.println("Subject Mark:" + sum + "-DI");
} else if (sum >= 60 && sum < 69) {
System.out.println("Subject Mark:" + sum + "-CR");
} else if (sum >= 50 && sum < 59) {
System.out.println("Subject Mark:" + sum + "-PA");
} else {
System.out.println("Less than 50 NN");
}
}

public void check(int num) {
boolean flag = true;
while (flag) {
if (num > 50 || num < 0) {
System.out.println("Invalid mark, Re-enter mark!");
Scanner sn = new Scanner(System.in);
if (num == num1) {
System.out
.println("Enter mark out of 50 for Assessment task 0:");
} else {
System.out
.println("Enter mark out of 50 for Assessment task 1:");
}

num = sn.nextInt();
} else {
flag = false;
}
}
}
}

3. java测试题

public static void main(String[] args) {
int x = 0, y = 0, z = 0;

BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

try {
System.out.println("please input X (X > 0):");
x = Integer.valueOf(bf.readLine());

if (x <= 0 ) {
System.out.println("X is OutOfBound.");
System.exit(1);
}

System.out.println("please input Y(1 < Y < 100):");
y = Integer.valueOf(bf.readLine());

if (y <= 1 || y >= 100) {
System.out.println("Y is OutOfBound.");
System.exit(1);
}

System.out.println("please input Z (Z > 0):");
z = Integer.valueOf(bf.readLine());
if (z <= 0 ) {
System.out.println("Z is OutOfBound.");
System.exit(1);
}
} catch (NumberFormatException nfe) {
nfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}

// with x create random
Random random = new Random();
int[] array = new int[x];

System.out.print("print:");
for (int i = 0; i < array.length; i++) {
array[i] = random.nextInt(100);
System.out.print(array[i] + " ");
}

System.out.println("");

List<Integer> list = new ArrayList<Integer>(0);
int i = 0;
while (i < array.length) {
int j = i;
for (; j < array.length; j ++) {
if (array[j] > y) {
list.add(array[j]);
} else {
break;
}
}

i = j + 1;

if (list.size() > z) {
for (int k = 0 ; k < list.size() ; k++) {
System.out.print(list.get(k) + " ");
}
System.out.println("");
}

list = new ArrayList<Integer>(0);
}
}

阅读全文

与java测试填空的文档相关的资料

热点内容
itunes备份包含微信聊天记录 浏览:20
怎么向虚拟机传文件 浏览:677
win10怎么用软件激活不了 浏览:816
美版a1453是什么版本 浏览:517
电脑里的文件夹按照拼音归类 浏览:996
文件管理器怎么把视频压缩成文件 浏览:477
标准化文件名称包括哪些 浏览:85
win10不能读取dll文件 浏览:882
云骑士重装系统找不到usb字样文件 浏览:42
皖事通app社保年限在哪里看 浏览:65
为什么快影显示没网络 浏览:356
华为如何让手机升级提醒红1消失 浏览:345
我爱九九商城app 浏览:587
剑灵苍穹武器升级 浏览:248
微信钱包微粒贷 浏览:654
滚动字幕屏找不到文件 浏览:990
郑州青少年学编程哪个机构比较好 浏览:866
ps文件打开不是彩色的 浏览:781
监控硬盘格式化工具 浏览:512
下载新版本微信6311 浏览:440

友情链接