Basic Operators
- What is the output of this program?
public class Result
{
public static void main(String args[])
{
int p , q = 1;
p = 20;
if(p != 20 && p / 0 == 0)
System.out.println(q);
else
System.out.println(++q);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Output: 2
- What is the output of this program?
public class ternary_operator_Example
{
public static void main(String args[])
{
int a = 5;
int b = ~ a;
int c;
c = a > b ? a : b;
System.out.print(c);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Output: 5
- What is the output of this program?
public class bool_operator_Example
{
public static void main(String args[])
{
boolean p = true;
boolean q = !true;
boolean r = p | q;
boolean s = p & q;
boolean z = s ? q : r;
System.out.println(s + " " + z);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Operator | returns true if any one operand is true, thus ‘r = true | false’ is true. Operator & returns p true if both of the operand is true thus s is false. Ternary operator ?: assigns left of ‘:’ if condition is true and right hand of ‘:’ if condition is false. z is false thus z = s ? q : r , assigns r to z , z contains true.
output: false true
- What is the output of this program?
public class Relational_operator_Example
{
public static void main(String args[])
{
int num1 = 7;
int num2 = 6;
System.out.print(num1 > num2);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Operator > returns a boolean value. 5 is not greater than 6 therefore false is returned.
output: true
- Which of these statement is correct?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
True and false are keywords, they are non numeric values which do no relate to zero or non zero numbers. true and false are boolean values.