0% found this document useful (0 votes)
58 views3 pages

Data Types in Java: 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

This document discusses Java data types and provides examples of code snippets and their outputs. It contains questions about primitive data types like int and char, operators like ++ and -, and expressions. The key points are: - Code examples demonstrate how operators like ++, -, and / affect variable values. - Expressions combine operators and operands to evaluate to a value. - There are two main types of data types in Java: primitive types and object/class types. - Mathematical expressions can be written using operators like *, +, -, / in Java.

Uploaded by

ShumsBadwal
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)
58 views3 pages

Data Types in Java: 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

This document discusses Java data types and provides examples of code snippets and their outputs. It contains questions about primitive data types like int and char, operators like ++ and -, and expressions. The key points are: - Code examples demonstrate how operators like ++, -, and / affect variable values. - Expressions combine operators and operands to evaluate to a value. - There are two main types of data types in Java: primitive types and object/class types. - Mathematical expressions can be written using operators like *, +, -, / in Java.

Uploaded by

ShumsBadwal
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
You are on page 1/ 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