Answer:
The error generated when the code is compiled:
incompatible types: int cannot be converted to boolean
Explanation:
This error is generated because the variable userNum is being assigned the value of 2.
userNum= 2
here = is the assignment operator used to assign the value 2 to the variable userNum
But here we need to compare the values with the value 2. So in order to compare the values in IF statement, == is used which is called the equality operator, instead of =
So the corrected if statement is:
if(userNum==2)
So the program prompts the user to enter a value (0,1,2,3) which is read in the userNum. Next the if statement checks if that input value is equal to 2. Num is equal to two message is displayed in the output when the if condition evaluates to true and Else part is executed if the condition evaluates to false and Num is not two message is displayed in the output.
For example the user enters a value 1 then the following message will be displayed in the output:
Num is not two
If the user enters 2 then the following message will be displayed in the output:
Num is equal to two