0% found this document useful (0 votes)
2 views8 pages

Ch-4 - Operators in Java

The document provides an overview of operators in Java, including examples of expressions with various data types and their output values. It includes multiple-choice questions, true/false statements, and exercises on rewriting statements and using ternary operators. Additionally, it contains programming tasks to evaluate expressions and predict outputs based on given variable values.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Ch-4 - Operators in Java

The document provides an overview of operators in Java, including examples of expressions with various data types and their output values. It includes multiple-choice questions, true/false statements, and exercises on rewriting statements and using ternary operators. Additionally, it contains programming tasks to evaluate expressions and predict outputs based on given variable values.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ICSE-IX-Operators in Java (Jyotii– 7066603136)

Ch-4 Operators in Java

1. Write data type of output value with an example of the followings:


1. Expression with two int values. Answer:int
E.g.: 5/2 is 2 as int
2. Expression with an int and a long values.
E.g.: 5/2L is
3. Expression with an int value and a double value.
E.g.: 5/2.0 is
4. Expression with an int and a float values.
E.g.: 5/2f is
5. Expression with a long and a float values.
E.g.: 5L/2f is
6. Expression with a float and a double values.
E.g.: 5F/2.0 is
7. Expression with a char value an int value.
E.g.: ‘A’+1 is
8. Expression with two char values.
E.g.: ‘A’+‘B’ is
9. Relational expression:
E.g.: [Link](5>3); Output is_____.
10. Logical expression
E.g.: [Link](5>4&&5>3); Output:_____.
11. Expression with a String value:
E.g.: [Link]("Value is "+6+7); Output:____
12. Expression with a boolean value:
E.g.: true && 5>3 is

Multiple Choice Questions


a. The statement n += 4 is equivalent to:
1. ++n
2. n=n+4
3. n+1
4. none

b. What will be the output of a & b in the following, if int a, b; a=10; b=a++;
1. 10,10
2. 10,11
3. 11,10
4. 11,11

1
ICSE-IX-Operators in Java (Jyotii– 7066603136)

c. What will be the output of a++ when int a = -1;


1. 1
2. -1
3. 0
4. none
d. If int a = 25, b = 5, c = 0; what value is stored in c? When c = a % b;
1. 5.0
2. 5
3. 0
4. none
e. What is the result of the following in Java statement?
int m=8;
m*=8;
[Link]("The output =" + m);
1. 8
2. 64
3. 16
4. 88
f. double c;
int x, y, z;
x = 5; y = 10; z = 11;
c = x*y+z/2;
The value stored in c is:
1. 55.0
2. 55.5
3. 55
4. none
g. int m, p;
m = 5;
p = 0;
p = m-- + --m;
The output will be:
1. 11
2. 10
3. 8
4. 12
h. int a=7, p=0, q=0;
p= ++a + --a;
q -= p;
The output of q will be:
1. 13
2. 14
3. 15
4. -15

2
ICSE-IX-Operators in Java (Jyotii– 7066603136)

i. An operator taking only single operand for its operation is called ...........
1. A unary operator
2. A binary operator
3. A ternary operator
4. None of these

j. Which one of the following is not a binary operator?


1. AND
2. %
3. ==
4. !

k. Which one of the following is not a valid operator in Java?


1. <=
2. !==
3. !=
4. ==

l. The statement i = i + 1 is equivalent to ...........


1. i++
2. i += 1
3. ++i
4. All of these
m. For x = 5, the statement sum = ++x + 8 evaluates to ...........
1. sum = 13
2. sum = 14
3. sum = 15
4. sum = 16
n. The statement (1>0) && (1<0) evaluates to ...........
1. 0
2. 1
3. false
4. true
o. The statement (1>0) || (1<0) evaluates to ...........
1. 0
2. 1
3. false
4. true

p. The statement (1==1)? 1: 0 evaluates to ...........


1. 0
2. 1
3. false
4. true

3
ICSE-IX-Operators in Java (Jyotii– 7066603136)

q. The expression 13 % 3 gives the output ...........


1. 4
2. 3
3. 2
4. 1
r. The expression 13 / 3 gives the output ...........
1. 4
2. 3
3. 0
4. 1
s. The statement [Link]("six " + 3 + 3); gives the output ...........
1. six 33
2. six 6
3. 33 six
4. 6 six
t.
The expression 4 + 8 % 2 gives the output ...........
1. 6
2. 8
3. 4
4. None of these

Write the Java expressions for the following:


1. p = a2 + bc
2. m = a2 - b2 / (ab)
3. s = ut + (1/2)at2
4. f = uv / (u + v)
5. (a + b)2 + b
6. y = 2(lb + bh + lh)
7. a2 + b2
8. z = x3 + y3 - xy / 3
9. (a + b)2 + b
10. a2 + b2
11. z = x3 + y3 + (xy) / 3
12. f = a2 + b2 / a2 - b2
13. z = ab + bc + ca / 3abc
14. 0 <= x <= 50

4
ICSE-IX-Operators in Java (Jyotii– 7066603136)

Rewrite the following statements without using shorthand operators.


a. p /= q 
b. p -= 1 
c. p *= q + r 
d. p -= q – r 

True or False
1. Arithmetic operators + and - also have a unary form.
2. Operators = and == perform the same operation in Java.
3. The expression 10 % 4 evaluates to 2.
4. The expression 3 / 4 evaluates to 0.
5. The expressions 3 + 4 and "3" + "4" evaluate to the same value.
6. The expression x = x + 7 is same as x =+ 7.
7. The new operator allocates memory during runtime.
8. The statements x = 7 and x == 7 are same.
9. The expression z =- 7 is same as z = z-7.
10. The assignment operator (=) is a binary operator.

Write output of the following:


1. If m=5 and n=2 then what will be the output of m and n after execution that will store in (a) &
(b)?
(a) m -= n;
(b) n = m + m/n;

2. If a = 5, b = 9, calculate the value of:


a += a++ - ++b + a

3. If x = 3, y = 7, calculate the value of:


x -= x++ - ++y

4. What will be the output of the following if x=5?


i. 5 * ++x
ii. 5 * x++

5. public class Test


{
public static void main(String[] args)
{
int a = 1, b = 2;
[Link]("Output1: " + a + b);
[Link]("Output2: " + (a + b));
}
}

5
ICSE-IX-Operators in Java (Jyotii– 7066603136)

6. What is the difference between the following two statements? Explain the results.
x -= 5;
x =- 5;

7. public class PredictOutput1


{
public static void main(String args[])
{
int a = 4, b = 2, c = 3;
[Link]("Output 1: " + (a = b * c));
[Link]("Output 2: " + (a = (b * c)));
}
}

8. public class PredictOutput2


{
public static void main(String args[])
{
int a = 6, b = 2, c = 3;
[Link]("Output 1: " + (a == b * c));
[Link]("Output 2: " + (a == (b * c)));
}
}

9. public class PredictOutput3


{
public static void main(String args[])
{
int a = 2, b = 2, c = 2;
[Link]("Output 1: " + (a + 2 < b * c));
[Link]("Output 2: " + (a + 2 < (b * c)));
}
}

10. int a=0,b=10,c=40;


a = --b + c++ +b;
[Link](" a = " + a);

11. int a=3,b=1,c=3;


a=a+ --b + ++c*b;
Ans :

6
ICSE-IX-Operators in Java (Jyotii– 7066603136)

12. int y=8;


y+= ++y + y-- + --y;
[Link](y);
Ans :
13. int x=5,x1;
x1=++x - x++ + --x;
[Link](x1+””+x);
Ans :
14. int a=10,z;
z=(++a*(a++ +5));
[Link](z)
Ans :
15. What will be the output of the following?
if x =5
(a) 5* ++x;
(b) 5* x++;
16. Evaluate the following expressions, if the values of the variables are:
a = 2, b = 3, and c = 9
(a) a - (b++) * (--c);
(b) a * (++b) % c;

17. If a = 5, b = 9, calculate the value of:


a += a++ - ++b + a;
18.
int a = 10, b =12;
if(a>=10)
a++;
else
++b;
[Link](" a = " + a + " and b = " +b);

Rewrite the following using ternary operator.


1. if(income<=100000)
tax = 0;
else
tax = (0.1*income);
2. if(p>5000)
d = p*5/100;
else
d = 2*p/100;
3. if(a>b)
[Link](“A is greater”);
Else
[Link](“B is greater”);

7
ICSE-IX-Operators in Java (Jyotii– 7066603136)

You might also like