Page 141 - computer science (868) class 11
P. 141
3. If mark=98;
String grade = (mark>=90) ? "A" : (mark>=80) ? "B" : "C";
What will be the output?
4. int a = 5;
a++;
System.out.println(a);
a = (a--) - (--a);
System.out.println(a);
What will be the output?
5. char al= 'k';
int as= al;
as=as+5;
System.out.println(as+ " : " +al);
What will be printed?
6. What will be the value of x1 if x=5, x1 = ++x - x++ + - -x; ?
7. Write down the Java expression for:
T=√a2+b4+c6 - (a*b)
8. Rewrite the following using the ternary operator.
if (x%2==0){
if (x >0)
System.out.print("EVEN POSITIVE NUMBER");
else
System.out.print("EVEN NEGATIVE NUMBER");
}
else
System.out.print("ODD");
9. What will be the output?
System.out.println((a & b) + (a | b));
if a = 15 and b=4;
10. If i=0, j=1;
What will be the output of bitwise OR?
11. Convert the following into a ternary operator and find the output.
int a=6, b=2, c=67;
if (a==b || (a>c))
System.out.println(c + a);
else
System.out.println(c-b);
12. What will be the result of the following?
int a= 10, b=4, c=77, d;
a. d = a++ + --b * (a++ - c--);
b. a += ++a /++b;
c. c -= b++ + b++ - c-- - --c;
d. a *= ++c;
e. d = a * (a++ - ++b) / 3;
D. Assertion and Reason type question.
Assertion: Conditional Assignment Operator is also known as Ternary Operator.
Reason: Ternary Operator consists of three operands which can be a variable, an expression or a constant.
(a) Both Assertion and Reason are true, and Reason is the correct explanation for
(b) Both Assertion and Reason are true, but Reason is not the correct explanation for Assertion.
(c) Assertion is true and Reason is false.
(d) Assertion is false and Reason is true.
139
Variables and Expressions 139

