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

2019-08-31 09:26

第 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(\

double)

is

invoked\if (num1 > num2) return num1; else return num2; }

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

System.out.println(\

int)

is

invoked\if (num1 > num2) return num1; else return num2; } }

1、 The program cannot compile because you cannot have the print statement in a non-void method.

2、 The program cannot compile because the compiler cannot determine which max method should be invoked.

3、 The program runs and prints 2 followed by \double)\is invoked.

System.out.println(\

long\

return n;


Java练习题1(有答案)(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2017-2018学年度第一学期小学教研工作计划及打算

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

马上注册会员

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