Home Java Java-tips Data Expressions Java: Numeric Expression Answers

Ask Questions?

View Latest Questions

Advertisement

Java: Numeric Expression Answers
Posted on: April 17, 2011 at 12:00 AM
This page discusses - Java: Numeric Expression Answers

# Numeric Expression Answers

Name ______________________

Assume the following:

```int i, j, k;
byte by;
double d;
float f;
k = 10;
j = 6;
f = 3.9F;
d = 6.2;
```
Give the values of the following expressions, or illegal.
 1 7 1 + 2 * 3 2 1 1 + 2 - 3 * 4 / 5 3 1 3 / 2 4 1.5 3 / 2.0 5 1.5 3.0 / 2 6 11 1+2 * 3+4 7 2 5 % 3 8 0 6 % 3 9 0 11 % 11 10 0 8 % 2 11 1 1 % 999 12 2 20%3*2/2 13 10 (((k))) 14 10 k++ 15 11 ++k 16 illegal 7++ 17 17 k++ + ++j 18 illegal k+++++j 19 illegal 3 = 4 20 false 3 == 4 21 illegal by = k 22 10 by = (byte)k 23 6 k = (int)j 24 10.0 f = k 25 illegal k = f 26 3 k = (int)f 27 3.9000000953674316 d = f 28 illegal f = d 29 6.199999809265137 f = (float)d 30 illegal f = 2.0 31 2000.0 f = 2.0e3F 32 1 by = 1 33 illegal k > j > 3 34 illegal k > j && > 3 35 true k > j && k > 3 36 5 k = j = 5 37 5 k = (j = 5) 38 illegal (k = j) = 5 39 11 k += 1 40 20 k *= 2 41 5 k /= 2 42 10 k = (k>j)?k:j+1 43 1 13 % 2 44 22 k++ + ++k 45 3 k = (int)f 46 -1 (k%2==0)?-1:1 47 false (int)(f + 0.5) == (int)d 48 true 22 == 22.0 49 false (0.1 + 0.1 + 0.1) == 0.3 50 5.551115123125783E-17 (0.1 + 0.1 + 0.1) - 0.3
Copyleft 2003 Fred Swartz MIT License, Last update: 2000-04-10
Advertisement