Run Time Exceptions - Computer Science

Card 0 of 2

Question

BITWISE XOR OPERATION

Given the following binary values

a = 0100 1110

b = 0011 0101

perform an XOR operation (c = a^b). What is the result?

Answer

Performing a bitwise excludive OR constitutes in taking both binary values and evaluating as follows: either one or the other (1) never both (0). This is the truth table for a bitwise XOR operation:

Blank flowchart   new page  2

Taking both a and b and performing the operation bit by bit we get the following result:

Result

Compare your answer with the correct one above

Question

True or False.

There is a runtime exception in this code snippet.

int wait_time = 0;

int wait_time = 5;

for (int i = 0; i < wait_time; i++) {

System.out.println(wait_time);

}

Answer

Yes, there is a runtime exception in the code snippet. The int wait_time is defined twice which will give a runtime exception. This can be fixed by not declaring int before the second assignment of the variable wait_time.

Compare your answer with the correct one above

Tap the card to reveal the answer