Page 138 - computer science (868) class 11
P. 138
7. The output of 5 ^ 3 is ………………… .
8. ………………… is used to shift bits of the first operand to right or left one by one.
9. The word ………………… determines the order in which the operators are executed in an expression.
Answers
1. Variable names 2. cannot 3. val-- 4. “Prefix Unary decrement Operator”
5. % (Remainder) 6. truth table 7. 6 8. Shift Operator 9. precedence
C. Answer the following questions:
1. Name the three types of arithmetic operators used in Java.
Ans. The three types of arithmetic operators are unary, binary, and ternary.
2. Name the different types of unary operators.
Ans. There are different types of unary operators. They are Unary(+), Unary(-), Unary increment(++) and Unary decrement (--).
3. Convert the following ternary operator to an if-else statement:
res=(num1>num2) ? (num1+num2):(num1-num2)
Ans. if(num1>num2)
res = (num1+num2);
else
res = (num1-num2);
4. Convert the following if-else statement to a ternary operator:
if(number > 0)
{
System.out.println("Positive Number");
}
else
{
System.out.println("Negative Number");
}
Ans. System.out.println((number > 0)?"Positive Number":"Negative Number");
5. Give the output of the following:
int exp1 = 0, exp2 = 5;
int result = 12 > 10 ? ++exp1 : ++exp2;
Ans. 1
6. Convert ternary operator to an if-else statement:
String res = num > 20 ? "Number is greater than 20" : num > 15 ? "Number is greater than
15" : "Number is less than equal to 15";
Ans. String res;
if(num > 20)
res="Number is greater than 20";
else
if(num >15)
res="Number is greater than 15";
else
res="Number is less than equal to 15";
7. What will be the output?
int a=11, b=22, c;
c = a + b + a++ + b++ + ++a + ++b;
System.out.println("c = "+c);
136136 Touchpad Computer Science-XI

