教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 实用模板 >

Java练习题1(有答案)(7)

来源:网络收集 时间:2026-01-29
导读: 4、 The program runs and prints 2 followed by \int)\is invoked. 5、 The program runs and prints \by 2. 答案 2 第 73题 The client can use a method without knowing how it is implemented. The details of

4、 The program runs and prints 2 followed by \int)\is invoked.

5、 The program runs and prints \by 2. 答案 2 第 73题 The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as __________. 1、 information hiding 2、 encapsulation 3、 method hiding

4、 simplifying method 答案 1 2 第 74

题 What is

Math.floor(3.6)? 1、 3.0 2、 3

3、 4 4、 5.0 答案 1 第 75题 If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________. 1、 3.4 2、 2.0 3、 3.4

4、 5.5 5、 undefined 答案 2 第 76题 If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is __________. e, 4 1、 0 2、 1

3、 2 4、 3 答案 4 第 77题 Suppose int i = 5, which of the following can be used as an index for array double[] t = new double[100]? 1、 i

2、 (int)(Math.random() * 100)) 3、 i + 10 4、 i + 6.5

5、 Math.random() * 100 答案 1 2 3 第 78题 Analyze the following code. public class Test { public static void main(String[] args) { int[] x = new int[3];

System.out.println(\ }

}

1、 The program has a compile error because the size of the array wasn t specified when declaring the array.

2、 The program has a runtime error because the array elements are not initialized.

3、 The program runs fine and displays x[0] is 0.

4、 The program has a runtime error because the array element x[0] is not defined. 答案 3 第 79题 What would be the result of attempting to compile and run the following code? public class Test { public static void main(String[] args) { double[] x = new double[]{1, 2, 3}; System.out.println(\ } }

1、 The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by {1, 2, 3}.

2、 The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[3]{1, 2, 3}; 3、 The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[]{1.0, 2.0, 3.0}; 4、 The program compiles and runs fine and the output \printed.

5、 The program compiles and runs fine and the output \is 2.0\答案 5 第 80题 Analyze the following code: public class Test { public static void main(String[] args) { int[] x = new int[5];

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

System.out.println(x[i]); } }

1、 The program displays 0 1 2 3 4. 2、 The program displays 4.

3、 The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException.

4、 The program has a compile error because i is not defined in the last statement in the main method.

答案 3 第 81题 In the following code, what is the printout for list2?

class Test { public static void

main(String[] args) { int[] list1 = {1, 2, 3}; int[] list2 = {1, 2, 3}; list2 = list1; list1[0] = 0; list1[1] = 1; list2[2] = 2; for (int i = 0; i < list2.length; i++)

System.out.print(list2[i] + \ } }

1、 1 2 3 2、 1 1 1 3、 0 1 2

4、 0 1 3 答案 3 第 82题 In the following code, what is the printout for list1? class Test { public static void

main(String[] args) { int[] list1 = {1, 2, 3}; int[] list2 = {1, 2, 3}; list2 = list1; list1[0] = 0; list1[1] = 1; list2[2] = 2; for (int i = 0; i < list1.length; i++)

System.out.print(list1[i] + \ } }

1、 1 2 3 2、 1 1 1

3、 0 1 2 4、 0 1 3 答案 3 第 83题 Analyze the following code: public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for } }

1、 The program displays 1 2 3 4 2、 The program displays 0 0

(int

i

=

0;

i

<

x.length;

i++)

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

3、 The program displays 0 0 3 4 4、 The program displays 0 0 0 0 答案 2 第 84题 Analyze the following code: public class Test { public static void main(String[] args) { final int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2];

for (int i = 0; i < y.length; i++) System.out.print(y[i] + \ } }

1、 The program displays 1 2 3 4 2、 The program displays 0 0

3、 The program has a compile error on the statement x = new int[2], because x is final and cannot be changed.

4、 The elements in the array x cannot be changed, because x is final. 答案 3 第 85题 Analyze the following code: public class Test { public static void main(String[] args) { int[] a = new int[4]; a[1] = 1; a = new int[2];

System.out.println(\ } }

1、 The program has a compile error because new int[2] is assigned to a. 2、 The program has a runtime error because a[1] is not initialized. 3、 The program displays a[1] is 0. 4、 The program displays a[1] is 1. 答案 3 第 86题 Show the output of the following code: public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4, 5}; increase(x); int[] y = {1, 2, 3, 4, 5}; increase(y[0]);

System.out.println(x[0] + \ } public static void increase(int[] x) { for (int i = 0; i < x.length; i++) x[i]++; } public static void increase(int y) { y++; } } 1、 0 0 2、 1 1 3、 2 2

4、 2 1 5、 1 2 答案 4 第 87题 programs produce the same result? Program I:

public class Test { public static void main(String[] args) { int[] list = {1, 2, 3, 4, 5}; reverse(list);

for (int i = 0; i < list.length; i++) System.out. …… 此处隐藏:3284字,全部文档内容请下载后查看。喜欢就下载吧 ……

Java练习题1(有答案)(7).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/521351.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)