Computer Knowledge

Programming Output Evaluation

1,721 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. output Positive infinity

  2. output Negative infinity

  3. Will fail to compile

  4. Runtime exception

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

Dividing a positive double by negative zero in Java yields negative infinity (-0.0 or negative infinity representation). Therefore, the comparison d == Double.POSITIVE_INFINITY evaluates to false, and the code prints Negative infinity.

Multiple choice technology programming languages
  1. 2

  2. 0

  3. 3

  4. 2.5

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

The key issue here is that (1 / 4) performs integer division, which results in 0, not 0.25. Then 0 * 10 = 0, so f = 0.0. Math.round(0.0) returns 0, which is printed out. This demonstrates the importance of understanding that integer division truncates toward zero in Java, which can lead to unexpected results when mixed with floating-point operations.

Multiple choice technology programming languages
  1. . Compiler error.

  2. Will throw a NoSuchMethod error at runtime.

  3. It will compile and run printing out "10"

  4. It will run with no output.

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

The code has a static block that calls print(10), which should work since print is a static method. However, the issue is that the static block runs before the main method, and the code has no main method at all. When you try to run this class, the JVM looks for a main method and throws a NoSuchMethodError at runtime because main() is missing. The static block will execute (and would print 10 if main existed), but the program fails due to the missing entry point.

Multiple choice technology programming languages
  1. -23

  2. -22.0

  3. 22.0

  4. 24

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

Math.ceil returns the smallest integer greater than or equal to its argument. For negative numbers, ceiling rounds toward zero (less negative), so ceil(-22.22222) = -22.0, not -23 (which would be floor). The method returns a double type, so the output is -22.0.

Multiple choice technology programming languages
  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

The code tests reference and value equality. sb1 == sb2 is false (different objects). StringBuffer doesn't override equals(), so sb1.equals(sb2) is false (uses Object.equals()). sb1.equals(ss1) is false (StringBuffer vs String - different types). 'Poddar'.substring(3) returns 'dar' (0-indexed, starts from 'd'). Output: false false false dar

Multiple choice technology web technology
  1. prints false

  2. prints true

  3. Complier error

  4. None of the above

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

According to the IEEE 754 standard for floating-point arithmetic, which Java adheres to, positive zero and negative zero are mathematically and logically considered equal. Therefore, the comparison 0.0 == -0.0 evaluates to true, and the program prints "true" rather than false.

Multiple choice technology web technology
  1. will Print Equal

  2. will Print Not Equal

  3. compile time error

  4. none of the above

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

The replace method creates and returns a new String object because a modification occurred. The == operator compares object references rather than their actual text content. Since two distinct string objects are created in memory, the reference comparison evaluates to false, resulting in "Not Equal" being printed.

Multiple choice technology programming languages
  1. an IntegerArithmeticException

  2. an ArithmeticException

  3. a DivideByZeroException

  4. a NumberFormatException

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

Java throws an ArithmeticException when an exceptional arithmetic condition has occurred, such as integer division by zero. Other options like IntegerArithmeticException and DivideByZeroException do not exist in the standard Java library, while NumberFormatException is thrown when attempting to convert an invalid string to a numeric type.

Multiple choice technology programming languages
  1. To add numbers together

  2. To keep track of data in the memory of the computer

  3. To print words on the screen

  4. To write Java

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

Variables exist to store data in memory, allowing programs to keep and manipulate values. The other choices describe specific operations (adding, printing, writing code) that are not the fundamental purpose of variables.

Multiple choice technology programming languages
  1. 4

  2. 5

  3. 6

  4. 8

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

To solve this question, the user needs to understand the concept of variable assignment and increment operators.

In the given code, we first declare an integer variable named "length" and assign it a value of 4. Then we use the increment operator "++" to increase the value of "length" by 1.

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

A. 4: This option is incorrect because the value of "length" is changed by using the increment operator. Therefore, the final value of "length" is not the same as its initial value of 4.

B. 5: This option is correct. The initial value of "length" is 4, and then we increment it by 1 using the "++" operator. Therefore, the final value of "length" is 5.

C. 6: This option is incorrect because if we use two increment operators in succession, then the value of "length" would be 6. However, in this code, there is only one increment operator, so the final value of "length" is 5.

D. 8: This option is incorrect because there is no operation in the given code that would result in the value of "length" being 8. The initial value of "length" is 4, and then we increment it by 1, resulting in a final value of 5.

Therefore, the correct answer is:

The Answer is: B. 5

Multiple choice technology programming languages
  1. null

  2. life

  3. universe

  4. everything

  5. Compilation fails

  6. An exception is thrown at runtime

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

The nested ternary first checks i<40 (false), then i>50 (false), so the final else clause is chosen. Hence s is assigned "everything". All other options are incorrect because the conditions do not match the value 42.

Multiple choice technology programming languages
  1. test case

  2. production

  3. test case live2

  4. Compilation fails

  5. An exception is thrown at runtime

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

The bitwise OR operator | evaluates both operands, so when args.length==1, Java still attempts args[1].equals("test"), causing ArrayIndexOutOfBoundsException. Logical OR || would short-circuit and avoid this. Only one argument "live2" was passed.

Multiple choice technology programming languages
  1. 5 1

  2. 5 2

  3. 5 3

  4. 8 1

  5. 8 2

  6. 8 3

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

Assuming the intended variable is x++, the loop runs five times. ++x and ++y increment before comparison; the first two iterations increment both without triggering the body. From the third iteration onward, ++x exceeds 2, short‑circuiting the || and preventing ++y, then x is incremented again. Final values are x=8, y=2, yielding "8 2".