Question: Java Test 16) What is the number of iterations in the following loop: for (int i = 1; i < n; i++) { // iteration
Java Test
16) What is the number of iterations in the following loop: for (int i = 1; i < n; i++) { // iteration } 16) A) 2*n B) n C) n + 1 D) n - 1
17) Analyze the following fragment: double sum = 0; double d = 0; while (d != 10.0) { d += 0.1; sum += sum + d; }
A) The program never stops because d is always 0.1 inside the loop. B) After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9 C) The program does not compile because sum and d are declared double, but assigned with integer value 0. D) The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.
18) What is Math.rint(3.5)?
18) A) 3.0 B) 5.0 C) 4.0 D) 3 E) 4
19) Which of the following should be declared as a void method?
A) Write a method that checks whether current second is an integer from 1 to 100.B) Write a method that prints integers from 1 to 100. C) Write a method that converts an uppercase letter to lowercase. D) Write a method that returns a random integer from 1 to 100.
20) Given the following method static void nPrint(String message, int n) { while (n > 0) { System.out.print(message); n- -; } } What is k after invoking nPrint("A message", k)? int k = 2; nPrint("A message", k);
20) A) 2 B) 0 C) 1 D) 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
