Professional Documents
Culture Documents
3 Operators
3 Operators
Give one point of difference between unary and binary operators. 2012
Ans.
A unary operator requires a single operand whereas a binary operator requires two operands.
Examples of Unary Operators – Increment ( ++ ) and Decrement ( — ) Operators
Examples of Binary Operators – +, -, *, /, %
Write a difference between unary and binary operator2019
Operators with higher precedence are evaluated before operators with relatively lower
precedence. Arrange the operators given below in order of higher precedence to lower
precedence. 2014
(i) &&
(ii) %
(iii) >=
(iv) ++
Ans
(iv), (ii), (iii), (i)
Write an expression in Java for z = (5×3 + 2y ) / ( x + y) 2011
Ans.
z = ( 5 * Math.pow ( x, 3 ) + 2 * y ) / ( x + y )
Ans
Ans
Math.abs(x*x +2*x*y) or Math.abs(Math.pow(x,2)+ 2*x*y)
What will be the result stored in x after evaluating the following expression?
int x=4;
x += (x++) + (++x) + x;
Ans.
x = x + (x++) + (++x) + x
x=4+4+6+6
x = 20
What is the value of y after evaluating the expression given below? 2018
y+= ++y + y-- + -- y; when int y=8
Ans
33
Evaluate the following expression if the value of x=2, y=3 and z=1. 2019
v=x+ --z+ y++ +y
Ans
v=9
What is the result stored in x, after evaluating the following expression 2010
int x = 5;
x = x++ * 2 + 3 * –x;
Ans. x = 5 * 2 + 3 * -6
x = 10 – 18
x = -8
What will be the output of the following code? 2010
char x = 'A' ; int m;
m=(x=='a') ? 'A' : ‘a’;
System.out.println("m="+m);
Ans
m=97
What will be the output of the following code? 2011
int k = 5, j = 9;
k += k++ – ++j + k;
System.out.println("k= " +k);
System.out.println("j= " +j);
Ans.
k = 6 , j = 10
Explanation:
k += k++ – ++j + k
k = k + k++ – ++j + k
k = 5 + 5 – 10 + 6
k=6
j = 10 as it has been incremented in the ++j operation.
What are the values of x and y when the following statements are executed?
int a = 63, b = 36;
boolean x = (a < b ) ? true : false; int y= (a > b ) ? a : b ;
Ans. x = false
y = 63
Give the output of the following method: 2014
public static void main(String[] args)
{
int a = 5;
a++;
System.out.println(a);
a-=(a--)–(--a);
System.out.println(a); }
Ans
6-(6-4)=4
If int y=10 then find int z=(++y*(y++ +5)); 2015
Ans
int z=(++y*(y++ +5));
(11*(11+5));
176