TCS
Company
Programming
Output
What will be the output?
public class Main
{
public static int main(String args[])
{
int x = 10;
int y = 10;
if (x^y)
System.out.println(" x is equal to y ");
return 0;
}
}
A. Nothing will print
B. Compile time error
C. x is equal to y
D. Runtime Error​
Read Solution (Total 5)
-
- it is bitwise XOR operator and hence given output as 0 based on given input. So if will not execute and code will print nothing
- 2 years agoHelpfull: Yes(1) No(0)
- B. Compile time error
if (x^y) --error - 3 years agoHelpfull: Yes(0) No(0)
- We get following Compile time error:
error: incompatible types: int cannot be converted to boolean
if (x^y)
^
Hence, B is correct option.
Reason: The syntax of basic if statement is:
if(boolean_expression) then statement
boolean_expression value should be TRUE, FALSE, or NULL. But in the above program x^y gives value 0 which is int, hence the error.
Reference: https://docs.oracle.com/database/121/LNPLS/if_statement.htm - 3 years agoHelpfull: Yes(0) No(0)
- Ans: B
Error in if(x^y) condition. - 3 years agoHelpfull: Yes(0) No(0)
- A. Nothing will print
- 1 year agoHelpfull: Yes(0) No(1)
TCS Other Question