CHAPTER_4_CLASS_X
CHAPTER_4_CLASS_X
CHAPTER_4_CLASS_X
class - x
Question 2
Question 3
Question 4
Given: int m=5; m*=5 then the value stored in m results in 55.
False
Question 5
Question 6
Question 7
Question 8
In the precedence of logical operators; NOT is followed by AND.
True
z = 5x3 + 2yx + y
Answer
z=5*x*x*x+2*y*x+y
Question 2
m = a2 + b2 / (a + b)
Answer
m = (a * a + b * b) / (a + b)
Question 3
s = ut + (1/2)at2
Answer
s = u * t + (1 / 2) * a * t * t
Question 4
f = uv / (u + v)
Answer
f = u * v / (u + v)
Question 5
d = √(3x + x2) / a + b
Answer
d = Math.sqrt(3 * x + x * x) / (a + b)
Question 6
p = a2 + b2 + 2ab
Answer
p=a*a+b*b+2*a*b
Question 7
y = 2(lb + bh + lh)
Answer
y = 2 * (l * b + b * h + l * h)
Question 8
p = a / b2 + b / a2
Answer
p = a / (b * b) + b / (a * a)
Question 9
z = x3 + y3 - y / z3
Answer
z = x * x * x + y * y * y - y / (z * z * z)
Question 10
q = 1 / √(a + b) + 3 / c2
Answer
q = (1 / Math.sqrt(a + b)) + 3 / (c * c)
Output
12
Explanation
As 3 is less than 4 so condition of ternary operator is true. Variable c is assigned the value of
expression 1 which is 3 * 4 = 12.
Question 2
int a = 14, b = 4;
boolean x = (a > b) ? true : false;
Output
true
Explanation
As 14 is greater than 4 so condition of ternary operator is true. Variable x is assigned the value of
expression 1 which is true.
Question 3
int x = 90;
char c = (x<=90)?'Z':'I';
Output
Explanation
Question 4
Output
false
Explanation
The condition a > 20 is false as value of a is 18. So the logical AND operator — && returns
false. Variable t is assigned the value of expression 2 which is false.
Question 5
Output
(a) 200
(b) 400
Explanation
When val = 1000, val + 550 = 1550. As 1550 is less than 1700 so condition of ternary operator is
true. Variable c is assigned the value of expression 1 which is 200.
When val = 1500, val + 550 = 2050. As 2050 is greater than 1700 so condition of ternary
operator is false. Variable c is assigned the value of expression 2 which is 400.
What is an operator? What are the three main types of operators? Name them.
Answer
Question 2
Answer
Question 3
Answer
Arithmetic operators are used to perform mathematical operations on its operands.
Operands of arithmetic operators must be of numeric type. A few arithmetic operators
operate upon one operand. They are called Unary Arithmetic operators. Other arithmetic
operators operate upon two operands. They are called Binary Arithmetic operators. As an
example consider the below statement:
int a = 10 + 20;
Here, the addition arithmetic operator, represented by the symbol + will add 10 and 20. So
variable a will be 30.
Answer
Relational operators are used to determine the relationship between the operands.
Relational operators compare their operands to check if the operands are equal to ( == ),
not equal to ( != ), less than ( < ), less than equal to ( <= ), greater than ( > ), greater than
equal to ( >= ) each other. The result of an operation involving relation operators is a
boolean value — true or false.
Example:
int a = 8;
int b = 10;
boolean c = a < b;
Here, as a is less than b so the result of a < b is true. Hence, boolean variable c becomes
true.
Answer
Logical operators operate on boolean expressions to combine the results of these boolean
expression into a single boolean value.
Example:
int a = 7;
int b = 10;
boolean c = a < b && a % 2 == 0;
Here, the result of first boolean expression a < b is true and the result of second boolean
expression a % 2 is false. The logical AND operator ( && ) combines these true and false
boolean values and gives a resultant boolean value as false. So, boolean variable c
becomes false.
Answer
Question 4
Distinguish between:
Answer
Answer
Answer
Answer
(p != q) !(p == q)
This expression uses the relational This expression first checks if values of p and q are equal
operator != (Not equal to) to using the relation operator == (equality). It then inverts the
determine if values of p and q are result of equality operator using the logical NOT (!) operator
different. to determine if values of p and q are different.
Question 5
Answer
/ %
Division operator Modulus operator
Returns the quotient of division operation Returns the remainder of division operation
Example: int a = 5 / 2; Here a will get the value Example: int b = 5 % 2; Here b will get the value
of 2 which is the quotient of this division of 1 which is the remainder of this division
operation operation
(b) = and == ?
Answer
= ==
It is the assignment operator used for It is the equality operator used to check if a variable is
assigning a value to a variable. equal to another variable or literal.
Example:
Example: if (a == 10)
int a = 10;
This statement checks if variable a is equal to 10 or
This statement assigns 10 to variable a.
not.
Question 6(a)
Output
k=6
j=10
Explanation
⇒ k = k + (k++ - ++j + k)
k+= k++ - ++j + k
⇒ k = 5 + (5 - 10 + 6)
⇒k=5+1
⇒k=6
Question 6(b)
Output
z = 176
Explanation
⇒ z = (11 * 16)
⇒ z = 176
Question 6(c)
Output
a = 39
Explanation
⇒ a = 7 + (7 + 9 + 8 + 8)
⇒ a = 7 + 32
⇒ a = 39
Question 6(d)
Output
y = 33
Explanation
⇒ y = 8 + (9 + 9 + 7)
⇒ y = 8 + 25
⇒ y = 33
Question 7
Rewrite the following program segment using if-else statements instead of the ternary operator.
Answer
String grade;
if (marks >= 90)
grade = "A";
else if (marks >= 80)
grade = "B";
else
grade = "C";
Answer
Answer
if (salary > 10000)
net = salary - (8.33/100) * salary;
else
net = salary - (5/100) * salary;
Answer
(e) c = (x >= 'A' && x<= 'Z') ? "Upper Case Letter" : "Lower Case Letter";
Answer
Question 8
(a)
if (x % 2 == 0)
System.out.println("Even");
else
System.out.println("Odd");
Answer
(b)
Answer
(c)
if(income < 10000)
tax = 0;
else
tax = 12;
Answer
(d)
if(a > b)
{
if (a > c)
g = a;
else
g = c;
}
else if (b > c)
g = b;
else
g = c;
Answer
(e)
if (p >= 4750)
k = p * 5 / 100;
else
k = p * 10 / 100;
Answer