0

programming languages Online Quiz - 96

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

"What will be the output of the following snippet: MOVE ZERO TO WS-COUNT IF WS-COUNT = 0 CONTINUE END-IF ADD +1 TO WS-COUNT. DISPLAY 'VALUE OF WS-COUNT: ' WS-COUNT "

  1. VALUE OF WS-COUNT: 0

  2. VALUE OF WS-COUNT: 1

  3. Compile error

  4. None of the above


Correct Option: A

"What will be the output of the following snippet: MOVE ZERO TO WS-COUNT IF WS-COUNT = 0 NEXT SENTENCE END-IF ADD +1 TO WS-COUNT. DISPLAY 'VALUE OF WS-COUNT: ' WS-COUNT "

  1. VALUE OF WS-COUNT: 0

  2. VALUE OF WS-COUNT: 1

  3. Compile error

  4. None of the above


Correct Option: A

The "switch" selection structure must end with the default case.

  1. True

  2. False


Correct Option: A
  1. Compilation error, attempting to perform binary comparison on logical data type.

  2. Compilation and output of "We are equal 10".

  3. Compilation and output of "Not equal! 20".

  4. Compilation and output of "Not equal! 10".


Correct Option: D

What results from attempting to compile and run the following code? public class Ternary { public static void main(String args[]) { int a = 5; System.out.println("Value is - " + ((a < 5) ? 9.9 : 9)); } }

  1. prints: Value is - 9

  2. prints: Value is - 5

  3. Compilation error

  4. None of these


Correct Option: D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) prints: Value is - 9 - This option is incorrect because the code will not print "Value is - 9". Instead, it will print "Value is - 9.0" because the expression (a &lt; 5) ? 9.9 : 9 evaluates to 9.9, which is a double value.

Option B) prints: Value is - 5 - This option is incorrect because the code will not print "Value is - 5". The value of the variable a is 5, but the ternary expression (a &lt; 5) ? 9.9 : 9 evaluates to 9.9, not 5.

Option C) Compilation error - This option is incorrect because the code will compile successfully without any errors. The code uses valid Java syntax.

Option D) None of these - This option is correct because the code will print "Value is - 9.0". The ternary expression (a &lt; 5) ? 9.9 : 9 evaluates to 9.9, which is a double value. The output will include the decimal point and ".0" because it is a double value.

Therefore, the correct answer is D) None of these.

What is the result when you compile and run the following code? public class Test { public void method() { for(int i = 0; i < 3; i++) { System.out.print(i); } System.out.print(i); } }

  1. 0122

  2. 0123

  3. Compilation error

  4. None of these


Correct Option: C

The modulus operator (%) in Java can be used only with variables of integer type.

  1. True

  2. False


Correct Option: B

AI Explanation

To answer this question, you need to understand the modulus operator (%) in Java and the types of variables it can be used with.

The modulus operator (%) in Java calculates the remainder of one number divided by another. While it is commonly used with integer types, it can also be used with other data types such as floating-point numbers (e.g., double and float).

So, the statement "The modulus operator (%) in Java can be used only with variables of integer type" is incorrect.

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

Option A) True - This option is incorrect because the modulus operator (%) in Java can be used with variables of other types, not just integer types.

Option B) False - This option is correct because the statement "The modulus operator (%) in Java can be used only with variables of integer type" is false.

The correct answer is B) False.

  1. The program will output 'scjp5_0.chap07.Ques01 1'.

  2. The program will output 1.

  3. The program will output '1' and then will raise an ArrayIndexOutOfBoundsException.

  4. The program won't print anything but will raise an ArrayIndexOutOfBoundsException at run-time.


Correct Option: B
- Hide questions