Quiz
178
Create a free account to finish this quiz
Save your progress and see your final score.
Already have an account? Sign in
Questions in this quiz (19)
11) You can always convert a while loop to a for loop.
- AA) true
- BB) false
2Will the following program terminate?int balance = 10;while (true) { if (balance < 9) break; balance = balance - 9;}
- AA) Yes
- BB) No
3You can always write a program without using break or continue in a loop.
- AA) true
- BB) false
4What is sum after the following loop terminates?int sum = 0;int item =
0;do { item++; sum += item; if (sum >= 4) continue;}while (item < 5);- AA) 18
- BB) 16
- CC) 15
- DD) 17
5 Analyze the following code.int count = 0;while (count < 100) {
// Point // Point
ASystem.out.println("Welcome to Java!"); B} // Point C- AA) count < 100 is always false at Point C
- BB) count < 100 is always false at Point B
- CC) count < 100 is always true at Point C
- DD) count < 100 is always true at Point A
- EE) count < 100 is always true at Point B
6 Is the following loop correct?for (; ; );
- AA) Yes
- BB) No
7What is sum after the following loop terminates?int sum = 0;int item = 0;do { item++; sum += item; if (sum > 4) break;}while (item < 5);
- AA) 7
- BB) 8
- CC) 6
- DD) 5
8How many times will the following code print "Welcome to Java"?int count = 0;do { System.out.println("Welcome to Java");} while (count++ < 10);
- AA) 11
- BB) 9
- CC) 0
- DD) 10
- EE) 8
9To add 0.01 + 0.02 + ... + 1.00, what order should you use to add the numbers to get better accuracy?
- Aadd 1.00, 0.99, 0.98, ..., 0.02, 0.01 in this order to a sum variable whose initial value is 0.
- Badd 0.01, 0.02, ..., 1.00 in this order to a sum variable whose initial
value is 0.
10 What is the number of iterations in the following loop: for (int i = 1; i
<= n; i++) { // iteration }- AA) n + 1
- BB) n - 1
- CC) 2*n
- DD) n
11Analyze the following statement:double sum = 0;for (double d = 0; d<10;) { d += 0.1; sum += sum + d;}
- AThe program has a syntax error because the adjustment is missing in the for loop.
- BThe program runs in an infinite loop because d<10 would always be true.
- CThe program has a syntax error because the control variable in the for loop cannot be of the double type.
- DThe program compiles and runs fine.
12 Analyze the following fragment:double sum = 0;double d = 0;while
(d != 10.0) { d += 0.1; sum += sum + d;}- AAfter the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9
- BThe program may not stop because of the phenomenon referred to
as numerical inaccuracy for operating with floating-point numbers - CThe program does not compile because sum and d are declared
double, but assigned with integer value 0. - DThe program never stops because d is always 0.1 inside the loop.
1313) Whatis1.0+1.0+1.0==3.0?
- AA) true
- BB) false
- CC) There is no guarantee that 1.0 + 1.0 + 1.0 == 3.0 is true.
14What is the output of the following fragment? for (int i = 0; i < 15; i++)
10) ______
11) ______
{
if (i % 4 == 1)
System.out.print(i + " ");- AA) 1 5 9 13 16
- BB) 1 4 8 12
- CC) 1 3 5 7 9 11 13
- DD) 1 3 5 7 9 11 13 15
- EE) 1 5 9 13
15 What is y after the following for loop statement is executed?int y = 0;for (int i = 0; i < 10; ++i) { y += 1; }
- A10
- B9
- C11
- D12
1616) What the output of the following code:for ( ; false ; ) System.out.println("Welcome to Java");
- Aprints out Welcome to Java two times.
- Bprints out Welcome to Java one time.
- Cdoes not print anything.
- Dprints out Welcome to Java forever.
17After the continue outer statement is executed in the following loop, which statement is executed?
outer: for(inti=1;i<10;i++){ inner: for(intj=1;j< 10; j++) { if (i * j > 50)
continue outer; System.out.println(i * j); } }next:- AThe program terminates.
- BThe control is in the inner loop, and the next iteration of the inner
loop is executed. - CThe control is in the outer loop, and the next iteration of the outer
loop is executed. - DThe statement labeled next.
18Will the following program terminate?int balance = 10;while (true) { if (balance < 9) continue; balance = balance - 9;}
- Atrue
- Bfalse
1919) What is the output for y?int y = 0;
for (int i = 0; i<10; ++i) {
y +=i; }
System.out.println(y);
- AA) 13
- BB) 45
- CC) 11
- DD) 10
- EE) 12
Information
- Description
- Quiz on 178, created by Juan Encarnocion on 15/02/2016.
- Author
- Juan Encarnocion
- Language
- English
- Views
- 0
- Rating
- No ratings yet Rate this quiz