You are on page 1of 3

DATA TYPES IN JAVA

Q1. If m=5 and n=2 output the values of m and n after execution in (i) and (ii) :i) m -= n;
ii) n = m + m/n
[2 marks]
A1.
i) 3
Working: m -= n
=> m = m n = 5 2 = 3
ii) 7
Working: n = m + m/n = 5 + 5/2 = 5 + 2 = 7
Q2. What will be the output of the following if x=5 initially?
i) 5 * ++x
ii) 5 * x++
[2 marks]
A2.
i) 30
Working: 5 * ++x = 5 * ++5 = 5 * 6 = 30
ii) 25
Working: 5 * x++ = 5 * 5++ = 5 * 5 = 25
Q3. What is the output of the following?
char c = 'A';
short m = 26;
int n = c+m;
System.out.println(n);
[2 marks]
A3. 91
Working: n = c+m = A + 26 = 65 + 26 = 91.

Q4. Differentiate between operator and expression. [2 marks]


A4.
OPERATOR

EXPRESSION
An expression is a combination of operators

An operator is a symbol that acts on one, two,

and operands.

or three operands to form an expression that


has a value.

For example, x + y is an expression which has the binary + operator that combines with two
operands x and y and adds their values to give a resultant value.
Q6. State the two kinds of data types. [2 marks]
A6. Primitive data types (e.g. int) and object data types of classes (e.g. String).
Q7. Write the corresponding expressions for the following mathematical operations:
i) a2 + b2
ii) z = x3 + y3 xy/z
A7.
i) a*a + b*b

ii) z= (x*x*x) + (y*y*y) ((x*y)/z)

You might also like