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
  1. 0

  2. 1

  3. 101

  4. 111

  5. 110

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

As instance variables, b1 and b2 are initialized to false. Thus, if tests on lines 7 and 9 are successful, so b1 is set to be true and x is incremented. The next test to succeed is on line 19 (note that the code is not testing to see if b2 is true, it is setting b2 to be true). Since line 19 was successful, subsequent else-if's (line 21) will be skipped. So, this is correct choice.

Multiple choice
  1. Welcome ava

  2. Welcome va

  3. Welcomeava

  4. Compiler error : delete cannot be used with StrinBuffer

  5. Run time error

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

This is the correct answer, delete(int start , int end) deletes the characters from the start index till end-1 index. So, the welcome to java will delete the characters from 8 to 11 characters. So the resulting string remains “ Welcome ava”. Index starts from 0. Hence, this is the correct answer.

Multiple choice
  1. s.length() = 14s.charAt(9) = T

  2. s.length() = 15s.charAt(9) = o

  3. s.length() = 15s.charAt(9) = T

  4. s.length() = 14s.charAt(9) = o

  5. Compiler Error

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

This is wrong. Length() function returns the number of characters in the string. As we can count that the number of characters in the given string are 15. So, length() will return 15 not 14. charAt() function returns the character at the given index in the parameter. Remember that the index count starts at 0. So, charAt(0) is W, counting in this way we reach charAt(9) is o not T.  Hence, this is the correct answer.

Multiple choice
  1. 0

  2. c

  3. Empty string

  4. Compile time error

  5. Run time error

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

This is wrong. Substring method takes two parameters (beginIndex,EndIndex).Substring( int Begin , int End). It returns the string from begin to end – 1. But, if the begin index is equal to the end index then an empty String with length 0 will be returned. So, here substring(4,4) will return an empty string of length 0. Hence, this is the correct answer.

Multiple choice
  1. Default Case Case 1 Case 2 Case 3

  2. Case 1Case 2Case 3

  3. Case 2Case 3

  4. Case 3

  5. Compilation Error

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

There is an error in the program because Math.round() function returns a “long” type of value and we cannot pass a “long” type of value in a switch() case. So the compiler will raise an error that “required:int, Found: long”. So this is the correct choice.

Multiple choice
  1. Default Case 1 Case 2 Case 3

  2. Case 1 Case 2 Case 3

  3. Case 2 Case 3

  4. Case 3

  5. Compiler Error

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

This is the correct choice because there is an error in the Program. Java doesn’t allow us to have Duplicate case labels in a Switch statement. In the given code, Case 2 and Case 3, both evaluate to the same value. So, when we try to compile the code, The compiler will raise an error, “duplicate case label”. So, this is the correct choice.

Multiple choice
  1. 25686.0

  2. 25656.0

  3. 65556.0

  4. 65536.0

  5. Compilation error

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

This is the correct choice. The value of variable i after evaluating the expression (1048576>>8>>3>>4>>3) comes out to be 4 and the value of variable y after evaluating the expression comes out to be 8. Both the values are passed to the function “ret(i,y)” to evaluate ret(4,8). This function finds the 4 raised to power 8 and prints that value on the screen.After evaluating the value comes out to be 65536.0. So this answer is correct.

Multiple choice
  1. Default Case 1Case 2Case 3

  2. Case1Case 2Case 3

  3. Case 2Case 3

  4. Case 3

  5. Compiler Error

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

This is the correct choice. The expression (int i = 1024<<8<<3>>8>>3;) given in theCode Evaluates to 1024. So the value of variable i is 1024. The expression will be evaluated as: (1024*(2^8)*(2^3)) / ((2^8)/(2^3)). So, the value of the variable I is now 1024. Now, switch will find a case label having value 1024 and all the Statements of that case will be evaluated. Case 3 is having the value 1024. So, “Case 3” is printed on the screen. So, this answer is correct.

Multiple choice
  1. Case -1Case 1Case 0

  2. Case -1Case 1

  3. Case 0

  4. Case 1

  5. Compiler error.

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

This is the correct answer. The expression given in the code (int i = 1048576>>8>>3>>8>>3;) will be evaluated as :-1048576 / (2^8) / (2^3) / (2^8) / (2^3). This will result into a 0.so the value of variable i becomes 0.Now switch(i++ - 1 ) will result into switch(0 -1), because we have used post-increment variable on variable i, so the value of variable i will be 0 at this time. So the switch case becomes:-Switch(-1).But we are using string values in case labels to find out the matching case. So the compiler will raise an error that “Required int, Found String”. So this answer is correct.

Multiple choice
  1. 13

  2. 9

  3. 12

  4. 16

  5. 22

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

This is the correct answer. The hypot() method in java takes two arguments as hypot(x,y) and it evaluates the expression :-   sqrt(x^2 +y^2). So, this will find sqrt(5,8) which comes out to be 9.433, so now the round() function will convert it to the nearest integer value, which is 9. So, this is the correct choice.

Multiple choice
  1. Case -1 Case 1

  2. Case -1Case 1Case 0

  3. Case 0

  4. No output

  5. Error at Line 1

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

This is the correct answer. The expression given in the code (int i = 1048576>>8>>3>>8>>3;) will be evaluated as :-1048576 / (2^8) / (2^3) / (2^8) / (2^3).This will result into a 0.so the value of variable i becomes 0. Now, switch(i++ - 1 ) will result into switch(0 -1), because we have used post-increment variable on variable i, so the value of variable i will be 0 at this time. So the switch case becomes:-Switch(-1).Now, the case label having value -1 will be executed, so “case -1” gets printed on screen. But there is no break statement after Case 1, so Case 2 statements will also get executed and we find a break after default. So no further statements will be executed.So this answer is true. The correct output is Case -1 Case 1.

Multiple choice
  1. 65536.0 12

  2. 65536.0 16

  3. 25536.012

  4. 25536.012

  5. Compiler Error

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

This is the correct choice. The value of variable i after evaluating the expression (1048576>>8>>3>>4>>3) comes out to be 4 and the value of variable y after evaluating the expression comes out to be 8.Both the values are passed to the function “ret(i,y)” to evaluate ret(4,8). This function finds the 4 raised to power 8 and prints that value on the screen.After evaluating the value comes out to be 65536.0. After that, System.out.println(i^y), statement will Apply XOR operation on the Values of variable i and y, and will print the result 12 on screen. So, the correct output is: 65536.0 12

Multiple choice
  1. No Valuei is 0i is 1

  2. i is 0i is 1

  3. i is 1

  4. No output

  5. Compilation Error

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

This is the correct choice, we have declared the variable i, but we didn’t initialise it to any value. So, the compiler will raise an Error that “i has not been initialised”. So, this answer is correct.

Multiple choice
  1. 32768

  2. 10242048

  3. 2048

  4. No Output

  5. Error at Line 1

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

This is the correct answer. The expression given in the code (int i = 1048576>>8>>3>>8>>3;) will be evaluated as :-1048576 / (2^8) / (2^3) / (2^8) / (2^3).This will result into a 0.so the value of variable i becomes 0. Now, switch(1 + i++ - 1 ) will result into switch(1 + 0 -1), because we have used post-increment variable on variable i, so the value of variable i will be 0 at this time. So the switch case becomes:-Switch(0).Now the Case having label 0 will get executed and it will solve the given expression (1024<<8<<3>>8>>3) as (1024*(2^8)(2^3)) / ((2^8)/(2^3)). So it will print 1024.As we don’t have any break after case 1. So case 2 statements will also get executed and the expression in case 2 (1024<<2>>3<<2) will be evaluated as (1024(2^2) / (2^3) *(2^2)) to result 2048.Now we encountered break after default case.So the program terminated here. So the correct output is :-10242048. So this answer is true.