Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Operators

What is the use and syntax of a ternary operator? 2009


Ans.
The ternary operator is a decision-making operator which can be used to replace certain if else
statement. Syntax: condition ? expression1 : expression2

What is difference between / and % operator? 2011


Ans.
/ is the division operator whereas % is the modulo (remainder) operator. a / b gives the result as
quotient obtained on diving a by b whereas a % b gives the remainder obtained on diving a by b.

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

Unary operator Binary operator


It works /Performs on single operand or It works/performs on two variables or
variables. OR Holds only one operand operands. OR Holds more than one operand

Name the operators listed below: 2017


(i) <
(ii) ++
(iii) &&
(iv) ?:
ans
(b)
(i) relational operator
(ii) unary increment operator
(iii) logical operator
(iv) ternary or conditional operator

Write one difference between / and % operator. 2017

/ – It is a division operator. It gives the quotient.


% – It is a modulus operator. It gives the remainder

What is meant by precedence of operators?


Ans.
Precedence of operators refers to the order in which the operators are applied to the operands in
an expression. For example, * has higher precedence than +. So, the expression 8 + 2 * 5 will
evaluate to 8 + 10 = 18

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 )

Write an expression for 2009

Ans

Write a Java expression for (√2as+u2)


Ans. 
Math.sqrt ( 2 * a * s + Math.pow ( u, 2 ) ) ( or ) Math.sqrt ( 2 * a * s + u * u )

Write a Java expression for the following:


| x2+ 2xy |

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

Write a Java expression for ut + ½ ft2 2013


Ans.
u * t + 0.5 * f * Math.pow ( t, 2)

Write the Java expression for: 2015


a 2 + b2
2ab
(i) (Math.pow(a,2)+Math.pow(b,2))/(2*a*b) [OR] (a*a+b*b)/(2*a*b)
Write a Java expression for the following: 2017
ax5 +bx3+c
Ans
a* Math.pow(x,5) +b*Math.pow( x,3)+c [OR] a*(x*x*x*x*x)+b*(x*x*x)+c
Write a Java expression for the following:
(√ 3 x + x 2) /(a+b) 2018
Ans Math.sqrt(3*x+x*x)/(a+b) OR Math.sqrt(3*x+Math.pow(x,2))/(a+b);

What is the value of x1 if x=5?


x1= ++x – x++ + --x
Ans
x1 = 6
System.out.print("BEST ");
System.out.println("OF LUCK");
Choose the correct option for the output of the above statements 2018
(i)BEST OF LUCK (ii)BEST
OF LUCK
Ans
(i) BEST OF LUCK

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

You might also like