What will be the output of the following code snippet?
int x = 10;
int y = 20;
if((x< y) || (x = 5) > 10)
System.out.println(x);
else
System.out.println(y);
Answers
Answer:
What will be the output of the following program?
public
class Test {
public
static void main(String[] args)
{
int x = 10;
if (x) {
System.out.println("HELLO GEEKS");
} else {
System.out.println("BYE");
}
}
}
Options:
1. HELLO GEEKS
2. Compile time error
3. Runtime Error
4. BYE
Output:
The answer is option (2).
Explanation: The argument of if statement should be Boolean type. By mistake if we are trying to provide any other data type then we will get compile-time error saying incompatible types. Here the argument is of int type, therefore we will get compile time error saying error: incompatible types: int cannot be converted to Boolean
Answer:
y=20
is the right answer of this question