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 java
  1. Compilation error: Divisions must be in a try block

  2. Compilation error: DivideByZeroException

  3. Runtime Exception

  4. No Error: a is NaN

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

In integer arithmetic, dividing by zero (9/0) throws a DivideByZeroException at runtime. If the numbers were floating-point (e.g., 9.0/0), the result would be Infinity, but the literal 9/0 is evaluated as integer division first, causing a runtime exception.

Multiple choice java
  1. Compilation error

  2. Runtime Error

  3. Runtime Exception

  4. Output of b is 1

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

The variable 'b' is an instance variable (non-static). The 'main' method is static. In Java and C#, static methods cannot directly access instance variables because instance variables require an object instance to exist. This results in a compilation error.

Multiple choice java
  1. Compiler error

  2. Runtime Exception

  3. True

  4. False

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

To solve this question, the user needs to understand the concept of object comparison in Java and how it differs from primitive type comparison.

In Java, objects are compared using the == operator. When comparing two objects using ==, Java checks if the two objects refer to the same memory location. If they do, the == operator returns true; otherwise, it returns false.

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

A. Compiler error: This option is incorrect. There is no compilation error in the given code. The code will compile successfully.

B. Runtime Exception: This option is incorrect. There is no runtime exception in the given code. The code will run without throwing any exceptions.

C. True: This option is incorrect. Although the values of a and b are both 2, the variables a and b are objects of the Integer class. When comparing objects using ==, Java checks if they refer to the same memory location, not their values. In this case, a and b are different objects, even though their values are the same. Therefore, a == b will return false.

D. False: This option is correct. As explained earlier, a and b are different objects, even though their values are the same. Therefore, a == b will return false.

The answer is: D. False

Multiple choice .net c-sharp
  1. myArray[1][3];

  2. myArray[1,3];

  3. myArray{1}{3};

  4. myArray(1),(3);

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

To output the value of a multidimensional array, you need to provide the indices for each dimension of the array. Let's go through each option and determine if it correctly outputs the value of a multidimensional array:

A. myArray[1][3]; This option is incorrect because it uses the wrong syntax to access the value of a multidimensional array. In C#, the correct syntax to access a value in a multidimensional array is myArray[1,3], not myArray[1][3]. The correct syntax uses commas to separate the indices for each dimension.

B. myArray[1,3]; This option is correct. It uses the correct syntax to access the value of a multidimensional array. The comma is used to separate the indices for each dimension, and this syntax correctly outputs the value at index 1 in the first dimension and index 3 in the second dimension of the array.

C. myArray{1}{3}; This option is incorrect because it uses curly braces instead of square brackets to access the value of the multidimensional array. In C#, square brackets [] are used to access array elements, not curly braces {}.

D. myArray(1),(3); This option is incorrect because it uses parentheses instead of square brackets to access the value of the multidimensional array. In C#, square brackets [] are used to access array elements, not parentheses ().

Therefore, the correct option is B. myArray[1,3].

Multiple choice sql
  1. Null

  2. 0

  3. Infinity

  4. An error is generated.

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

With ARITHABORT OFF and ANSI_WARNINGS OFF, SQL Server returns NULL for division by zero instead of raising an error. ARITHABORT controls query termination on arithmetic errors, while ANSI_WARNINGS controls NULL/division-by-zero behavior. When both are OFF, the result is NULL rather than an error or infinity.

Multiple choice java core java
  1. 1.11011

  2. 2.1121

  3. 3.11222

  4. 4.11235

  5. 5.11248

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

The loop computes Fibonacci-like values starting from index 2. Initial array: [1,1,0,0,0]. At i=2: arr[2]=arr[1]+arr[0]=1+1=2. At i=3: arr[3]=arr[2]+arr[1]=2+1=3. At i=4: arr[4]=arr[3]+arr[2]=3+2=5. Final array: [1,1,2,3,5], which as a string is 11235. Each element from index 2 onward is the sum of the two preceding elements.

Multiple choice java
  1. Object reference =null

  2. double =0.0

  3. byte=0

  4. char = '\u0000'

Reveal answer Fill a bubble to check yourself
A,B,C,D Correct answer
Explanation

Java has defined default values for uninitialized fields: Object references default to null, numeric primitives to 0 or 0.0, boolean to false, and char to '\u0000' (null character). All four options correctly state these default values for their respective types.

Multiple choice java
  1. y string = Java,y string = Java

  2. y string = Javay string = Java

  3. y string = Java, y string = Java

  4. y String = Java, y string = Java

Reveal answer Fill a bubble to check yourself
C Correct answer
Multiple choice string operation
  1. A. 0

  2. B. 2

  3. C. -1

  4. D. 4

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

To determine the value of fname after the given code fragment, we need to understand the indexOf() method in Java and how it is used.

The indexOf() method in Java returns the index of the first occurrence of a specified substring within a given string. It returns -1 if the substring is not found.

Now let's go through the code fragment and evaluate each line:

String str;
int fname;
str = ";Foolish boy.";
fname = str.indexOf("fool");
  • String str; declares a variable str of type String.
  • int fname; declares a variable fname of type int.
  • str = ";Foolish boy."; assigns the string ";Foolish boy." to the variable str.
  • fname = str.indexOf("fool"); assigns the return value of indexOf("fool") to the variable fname.

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

A. 0: This option is incorrect. The indexOf("fool") method call will return -1 because the substring "fool" is not found in the string str = ";Foolish boy.". Therefore, fname will be assigned the value -1, not 0.

B. 2: This option is incorrect. The indexOf("fool") method call will return -1 because the substring "fool" is not found in the string str = ";Foolish boy.". Therefore, fname will be assigned the value -1, not 2.

C. -1: This option is correct. The indexOf("fool") method call will return -1 because the substring "fool" is not found in the string str = ";Foolish boy.". Therefore, fname will be assigned the value -1.

D. 4: This option is incorrect. The indexOf("fool") method call will return -1 because the substring "fool" is not found in the string str = ";Foolish boy.". Therefore, fname will be assigned the value -1, not 4.

Therefore, the correct answer is:

C. -1

Multiple choice string
  1. A. Compile and display “Equal”

  2. B. Compile and display “Not Equal”

  3. C. Cause a compiler error

  4. D. Compile and display NULL

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

In Java, the trim() method returns a canonical string from the string pool if the resulting string is a literal. However, because trim() creates a new string object, == usually compares references. In many JVM implementations, this specific literal comparison might return true, but equals() is the proper way to compare content.

Multiple choice string
  1. A. ‘a’

  2. B. ‘v’

  3. C. throws StringIndexOutofBoundsException

  4. D. null characater

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

charAt() is zero-indexed. 'Java' has indices 0-3 (J=0, a=1, v=2, a=3). Index 4 is out of bounds, so StringIndexOutOfBoundsException is thrown. Option C is correct.