You are on page 1of 3

ARITHMETIC OPERATORS

EXERCISE #1
1. int x = 17;
int y = 10 – 4; // 6
x = x + y; // 23
int z = x / y; // 3
System.out.println( z % 2 ); // 1

2. int x = 7 + 4; // 11
int y = x – 2; // 9
y = y % 2; // 1
int z = y * 3; // 3
System.out.println( 14 / z ); // 4

3. int x = 2 * 2; // 4
int y = 13 % 5; // 3
y = y + x; // 7
System.out.println( y / 2 ); // 3

4. double x = 83 % 7; // 6.0
double y = 12 % x; // 0.0
y = y / x; // 0.0
System.out.println( y ); // 0.0

5. int x = 34 % 5; // 4
x = x + 4; // 8
System.out.println( x / 4 ); // 2

6. double x = 45.0 / 12; // 3.75


x = x * x; // 14.0625
System.out.println( x % 5 ); // 4.0625

7. float x = 23 * 4; // 92
x = x % 3; // 2
System.out.println( x / 5 ); // 0.4f

8. byte b = 23 + 3; // 26
b = (byte) (b % 3); // 2
System.out.println( b / 2 ); // 1

9. double x = 43 % 3; // 1
x = x * 43; // 43
System.out.println( x / 43 ); // 1.0

10. int x = 27 – 13; // 14


x = x % 4; // 2
System.out.println( 17 / (double) x ); // 8.5
RELATIONAL OPERATORS
EXERCISE #2
a. FALSE
b. TRUE
c. FALSE
d. TRUE
e. TRUE
f. TRUE
g. TRUE
h. TRUE
i. FALSE
j. FALSE
LOGICAL OPERATORS
EXERCISE #3
a. FALSE
b. FALSE
c. TRUE
d. TRUE
e. TRUE
f. TRUE
g. TRUE
h. FALSE
i. TRUE
j. TRUE
ASSIGNMENT OPERATORS
EXERCISE #4
a. 59
b. 11
c. 7
d. 41
e. 9
f. 84.0
g. 2
h. 12
i. 47
j. 78
ORDER OF PRECEDENCE
EXERCISE #5
a. 6
b. 33
c. 1
d. 2
f. 211
g. TRUE
h. TRUE
i. 92
j. 1
EXERCISE #6
a. 23
b. 33
c. 7
d. 135
e. 13
f. FALSE
g. FALSE
h. FALSE
i. TRUE
j. FALSE
EXERCISE #7
a. 18
b. -15
c. 6.5
d. 140
e. 1.7083
f. 85
g. 8.5
h. 60.5
i. 0.0
j. 0
EXERCISE #8
a. 1.5
b. 8.3
c. 64.5
d. 16.0
e. 6.36
f. 41.5
g. 141.0
h. 2.0
i. 17.5
j. 30.0
EXERCISE #9
a. TRUE
b. FALSE
c. FALSE
d. TRUE
e. TRUE
f. FALSE
g. FALSE
h. FALSE
i. TRUE
j. FALSE

You might also like