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

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

来源:网络收集 时间:2026-01-29
导读: 第 61题 To add 0.01 + 0.02 + ... + 1.00, what order should you use to add the numbers to get better accuracy? 1、 add 0.01, 0.02, ..., 1.00 in this order to a sum variable whose initial value is 0. 2

第 61题 To add 0.01 + 0.02 + ... + 1.00, what order should you use to add the numbers to get better accuracy?

1、 add 0.01, 0.02, ..., 1.00 in this order to a sum variable whose initial value is 0.

2、 add 1.00, 0.99, 0.98, ..., 0.02, 0.01 in this order to a sum variable whose initial value is 0.

答案 1 第 62题 What is sum after the following loop terminates? int sum = 0; int item = 0; do { item++; sum += item; if (sum > 4) break;

} while (item < 5); 1、 5 2、 6

3、 7 4、 8 答案 2 第 63题 After the continue outer statement is executed in the following loop, which statement is executed? outer: for (int i = 1; i < 10; i++) { inner:

for (int j = 1; j < 10; j++) { if (i * j > 50) continue outer; System.out.println(i * j); } } next:

1、 The control is in the outer loop, and the next iteration of the outer loop is executed.

2、 The control is in the inner loop, and the next iteration of the inner loop is executed.

3、 The statement labeled next.

4、 The program terminates. 答案 1 第 64题 Suppose the input for number is 9. What is the output from running the following program? import java.util.Scanner; public class Test {

public static void main(String[] args) { Scanner input = new Scanner(System.in);

System.out.print(\int number = input.nextInt(); int i;

boolean isPrime = true; for (i = 2; i < number && isPrime; i++) { if (number % i == 0) { isPrime = false; } }

System.out.println(\if (isPrime)

System.out.println(number + \is prime\else

System.out.println(number + \ } }

1、 i is 3 followed by 9 is prime 2、 i is 3 followed by 9 is not prime

3、 i is 4 followed by 9 is prime 4、 i is 4 followed by 9 is not prime 答案 4 第 65题 Suppose your method does not return any value, which of the following keywords can be used as a return type? 1、 void 2、 int 3、 double 4、 public

5、 None of the above 答案 1 第 66题 All Java applications must have a method __________. 1、 public static Main(String[] args) 2、 public static Main(String args[]) 3、 public static void main(String[] args)

4、 public void main(String[] args) 5、 public static main(String[] args) 答案 3 第 67题 Does the return statement in the following method cause compile errors?

public static void main(String[] args) { int max = 0; if (max != 0) System.out.println(max); else return; }

1、 Yes 2、 No 答案 2 第 68题 Does the method call in the following method cause compile errors?

public static void main(String[] args) { Math.pow(2, 4); }

1、 Yes 2、 No 答案 2 第 69题 Suppose

static void nPrint(String message, int n) { while (n > 0) {

System.out.print(message); n--; } }

What is the printout of the call nPrint( a , 4)? 1、 aaaaa 2、 aaaa 3、 aaa

4、 invalid call 答案 4 第 70题 Suppose

static void nPrint(String message, int n) { while (n > 0) {

System.out.print(message); n--; } }

What is k after invoking nPrint(\ int k = 2; nPrint(\message\ 1、 0 2、 1

3、 2 4、 3 答案 3 第 71题 Analyze the following code: public class Test { public static void main(String[] args) {

System.out.println(xMethod(5, 500L)); }

public static int xMethod(int n, long l) {

System.out.println(\

long\

return n; }

public static long xMethod(long n, long l) { } }

1、 The program displays int, long followed by 5. 2、 The program displays long, long followed by 5.

3、 The program runs fine but displays things other than 5.

4、 The program does not compile because the compiler cannot distinguish which xmethod to invoke. 答案 1 第 72题 Analyze the following code. public class Test { public static void main(String[] args) { System.out.println(max(1, 2)); }

public static double max(int num1, double num2) {

System.out.println(\ …… 此处隐藏:1409字,全部文档内容请下载后查看。喜欢就下载吧 ……

Java练习题1(有答案)(5).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)