0

programming languages Online Quiz - 129

Description: programming languages Online Quiz - 129
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

Each pass through a loop is called a/an

  1. enumeration

  2. iteration

  3. culmination

  4. pass through


Correct Option: B

Which looping process checks the test condition at the end of the loop?

  1. for

  2. while

  3. do-while

  4. no looping process checks the test condition at the end


Correct Option: C

A continue statement causes execution to skip to

  1. the next iteration of the loop

  2. the first statement after the loop

  3. the statement following the continue statement

  4. the return 0; statement


Correct Option: A

In a group of nested loops, which loop is executed the most number of times?

  1. the outermost loop

  2. the innermost loop

  3. all loops are executed the same number of times

  4. cannot be determined without knowing the size of the loops


Correct Option: B

AI Explanation

To answer this question, we need to understand how nested loops work.

Nested loops are loops that are placed inside another loop. The number of times each loop is executed depends on the number of iterations of the outer loop.

Let's go through each option to understand why it is correct or incorrect:

Option A) the outermost loop - This option is incorrect. The outermost loop determines the total number of iterations, but it doesn't necessarily mean it will be executed the most number of times. The number of iterations of the outermost loop is dependent on the number of iterations of the inner loops.

Option B) the innermost loop - This option is correct. The innermost loop will be executed the most number of times because it goes through all of its iterations for each iteration of the outer loops. In other words, for each iteration of the outer loop, the innermost loop will execute all of its iterations.

Option C) all loops are executed the same number of times - This option is incorrect. The number of times each loop is executed depends on the number of iterations of the outer loop. Therefore, all loops are not executed the same number of times.

Option D) cannot be determined without knowing the size of the loops - This option is incorrect. The number of times each loop is executed can be determined based on the structure of the nested loops, regardless of the size of the loops.

The correct answer is B) the innermost loop. This option is correct because the innermost loop will be executed the most number of times as it goes through all of its iterations for each iteration of the outer loops.

The statement i++; is equivalent to

  1. i = i + i;

  2. i = i - 1;

  3. i = i + 1;

  4. i --;


Correct Option: C

Which looping process is best used when the number of iterations is known?

  1. for

  2. while

  3. do-while

  4. all looping processes require that the iterations be known


Correct Option: A

What's wrong? for (int k = 2, k <=12, k++)

  1. the increment should always be ++k

  2. the variable must always be the letter i when using a for loop

  3. there should be a semicolon at the end of the statement

  4. the commas should be semicolons


Correct Option: D

What's wrong? while( (i < 10) && (i > 24))

  1. the logical operator && cannot be used in a test condition

  2. the while loop is an exit-condition loop

  3. the test condition is always false

  4. the test condition is always true


Correct Option: C

If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?

  1. parentheses ( )

  2. braces { }

  3. brackets [ ]

  4. arrows < >


Correct Option: B

What's wrong? (x = 4 && y = 5) ? (a = 5) ; (b = 6);

  1. the question mark should be an equal sign

  2. the first semicolon should be a colon

  3. there are too many variables in the statement

  4. the conditional operator is only used with apstrings


Correct Option: B

Each pass through a loop is called a/an

  1. enumeration

  2. iteration

  3. culmination

  4. pass through


Correct Option: B

AI Explanation

To answer this question, you need to understand the concept of loops in programming.

Option A) Enumeration - This option is incorrect because enumeration refers to the process of assigning a unique value to each element in a list or collection.

Option B) Iteration - This option is correct because each pass through a loop is called an iteration. In programming, loops are used to repeat a set of instructions until a certain condition is met.

Option C) Culmination - This option is incorrect because culmination refers to the climax or final stage of something, which is not related to loops.

Option D) Pass through - This option is incorrect because while it describes the process of going through something, it does not specifically refer to a loop.

The correct answer is option B) Iteration. This option is correct because each pass through a loop is called an iteration.

Which looping process checks the test condition at the end of the loop?

  1. for

  2. while

  3. do-while

  4. no looping process checks the test condition at the end


Correct Option: C

A continue statement causes execution to skip to

  1. the return 0; statement

  2. the first statement after the loop

  3. the statement following the continue statement

  4. the next iteration of the loop


Correct Option: D

AI Explanation

To answer this question, we need to understand the purpose and behavior of the continue statement in programming.

The continue statement is used within loops to skip the remaining code within the current iteration and move on to the next iteration of the loop. It is often used in conditional statements to skip certain iterations based on a specific condition.

Let's go through each option to understand why it is correct or incorrect:

Option A) the return 0; statement - This option is incorrect. The continue statement does not cause execution to skip to the return statement. Instead, it only affects the flow within the loop.

Option B) the first statement after the loop - This option is incorrect. The continue statement does not cause execution to skip to the first statement after the loop. It only affects the flow within the loop itself.

Option C) the statement following the continue statement - This option is incorrect. The continue statement does not cause execution to skip to the statement immediately after it. Instead, it only affects the flow within the loop.

Option D) the next iteration of the loop - This option is correct. The continue statement causes execution to skip to the next iteration of the loop, ignoring the remaining code within the current iteration.

Therefore, the correct answer is D. The continue statement causes execution to skip to the next iteration of the loop.

Read the following program: public class test { public static void main(String [] args) { int x = 3; int y = 1; if (x = y) System.out.println("Not equal"); else System.out.println("Equal"); } } What is the result?

  1. The output is “Equal”

  2. The output in “Not Equal”

  3. An error at " if (x = y)" causes compilation to fall.

  4. The program executes but no output is show on console.


Correct Option: C

How you can force the garbage collection?

  1. Using delete operator

  2. Using destructor

  3. Garbage collection is an automatic process & cant be forced.

  4. None of the above


Correct Option: C

Difference between Swing and AWT?

  1. AWT are light-weight componenets. Swings are heavy-weight components.

  2. AWT is platform independent. SWING is platform dependent.

  3. AWT are heavy-weight componenets. Swings are light-weight components.

  4. None of the above


Correct Option: C

Can I have multiple methods in the same class?

  1. True

  2. False


Correct Option: B

Which of the following are legal identifiers?

  1. 2variable

  2. variable2

  3. _whatavariable

  4. 3

  5. #myvar

  6. $anothervar


Correct Option: B,C,D,F

What will happen when you compile and run the following code? public class MyClass{ static int i; public static void main(String argv[]){ System.out.println(i); } }

  1. Error Variable i may not have been initialized

  2. null

  3. 1

  4. 0


Correct Option: D

What will happen if you try to compile and run the following code? public class Q { public static void main(String argv[]){ int anar[]=new int[5]; System.out.println(anar[0]); } }

  1. Error: anar is referenced before it is initialized

  2. null

  3. 0

  4. 5


Correct Option: C
- Hide questions