Computer Knowledge

Programming Output Evaluation

1,953 Questions

Programming output evaluation tests the ability to trace code execution in languages like C, Java, and SAS. It focuses on arrays, loops, pointers, and data type conversions. These technical questions are standard in computer knowledge sections for IT officer and bank exams.

Java string bufferC language pointersLoop execution outputsData type conversionsMacro variable evaluation

Programming Output Evaluation Questions

Multiple choice technology programming languages
  1. No output

  2. 3 and 5

  3. 1, 3 and 5

  4. 3

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

This switch statement demonstrates fall-through behavior. With x=2, execution jumps to case 2 (which has no statement), then falls through to case 3 and prints 3. Since there's no break, it continues to case 5 and prints 5. The output shows both 3 and 5 printed on separate lines.

Multiple choice technology programming languages
  1. -1

  2. 0

  3. 4

  4. random value

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To solve this question, the user needs to understand the behavior of the indexOf() method in Java. This method returns the index of the first occurrence of a specified substring within a given string. If the substring is not found in the string, the method returns -1.

In the given code fragment, the string s is initialized to "Foolish boy." and the indexOf() method is called on this string with the argument "fool". Note that the substring "fool" is not present in the original string with the same letter case. The index of the first occurrence of the substring "fool" in the string s is thus -1.

Therefore, the correct answer is:

The Answer is: A. -1

Multiple choice technology programming languages
  1. Integer "j" is not initialized.

  2. Nothing.

  3. You cannot declare integer i inside the for-loop declaration.

  4. The syntax of the "if" statement is incorrect.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To solve this question, the user should have knowledge of basic Java syntax and control flow statements.

The code is a basic for-loop that initializes an integer variable i to 0 and then increments it by 1 with each iteration until it reaches 13. Inside the loop, there is an if statement that checks if i is less than 10. If it is, it initializes an integer variable j to 2 + i. Then, it prints out the values of j and i.

Now, let's go through each option and explain why it is right or wrong:

A. Integer "j" is not initialized: This option is incorrect. The integer "j" is initialized inside the for-loop. Although it is not initialized before the loop, it is initialized before it is used.

B. Nothing: This option is incorrect. There is something wrong with the code.

C. You cannot declare integer i inside the for-loop declaration: This option is incorrect. The declaration of integer i inside the for-loop is valid Java syntax.

D. The syntax of the "if" statement is incorrect: This option is incorrect. The syntax of the if statement in the code is correct.

Therefore, the correct answer is:

The Answer is: B

Multiple choice technology programming languages
  1. 19 followed by 20

  2. 19 followed by 11

  3. Error: Can't convert java lang Integer

  4. 10 followed by 1

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The code attempts to add Integer and Long wrapper objects directly using the + operator. Java does not support automatic unboxing and arithmetic between different wrapper object types - Integer + Long is invalid. You must first convert them to primitive types using intValue() or longValue(). The compiler will error on 'ten + nine' because it cannot resolve the + operator for Integer and Long types. The second operation 'i + ten' would work because int auto-unboxes Integer, but the first error prevents compilation.

Multiple choice technology programming languages
  1. table is a variable to refers to a real number

  2. table is a variable that refers to two numbers

  3. It is not legal Java code

  4. table is a variable that refers to an array

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The declaration Double table[] is valid Java syntax for declaring an array variable. It specifies that table is a variable intended to reference an array of Double objects. It does not refer to a single real number or exactly two numbers, making the array choice correct.

Multiple choice technology mainframe
  1. Displays from 1 to 99 and program ends normally

  2. displays from 1 to 100 and program ends normally

  3. Program will terminate abnormally without displaying anything

  4. displays till 99 and program will terminate abnormally

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The loop increments #A from 1 to 99 (when #A=99, condition fails and it exits), then RESET fails because #A is already 99, causing abnormal termination. Options A and B are wrong because the program doesn't end normally.

Multiple choice technology web technology
  1. false false false dar

  2. false true false Poddar

  3. Compiler Error

  4. true true false dar

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

StringBuffer does not override equals() so it uses Object's equals() which compares references. sb1 and sb2 are different objects, so sb1==sb2 returns false and sb1.equals(sb2) also returns false. StringBuffer cannot be compared with String using equals(). "Poddar".substring(3) extracts characters from index 3 to end, giving "dar".

Multiple choice technology web technology
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

String literals are not automatically created as new instances. When Java encounters a string literal, it first checks the string pool. If the literal already exists in the pool, it returns the reference to that existing string. Only a new literal not found in the pool creates a new instance.

Multiple choice technology web technology
  1. Compile error

  2. amitPoddar O

  3. amitPoddar I

  4. amit I

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

s1 remains 'amit' because Strings are immutable and s1.concat is ignored. s2 becomes 'aiit'. s1+s2 is 'amitaiit'. The character at index 5 of 'amitaiit' (0-indexed: a=0, m=1, i=2, t=3, a=4, i=5) is 'i'. Thus, printing s1 gives 'amit', and the char is 'I' (capitalized in options).

Multiple choice technology web technology
  1. True true true false

  2. True true true true

  3. True false true false

  4. False false true false

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

String literals s1 and s2 refer to the same object in the string pool, so both equals() and == return true. Strings created with new operator (s3, s4) are separate objects, so s3==s4 returns false, but s3.equals(s4) returns true because equals() compares content.

Multiple choice technology web technology
  1. false false false dar

  2. false true false Poddar

  3. Compiler Error

  4. true true false dar

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is identical to question 141947. StringBuffer does not override equals(), so sb1.equals(sb2) returns false for different objects. sb1==sb2 is also false. StringBuffer cannot equal a String. "Poddar".substring(3) returns "dar".