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

Java Notes

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.
171 + 2 * 3
211 + 2 - 3 * 4 / 5
313 / 2
41.53 / 2.0
51.53.0 / 2
6111+2 * 3+4
725 % 3
806 % 3
9011 % 11
1008 % 2
1111 % 999
12220%3*2/2
1310(((k)))
1410k++
1511++k
16illegal7++
1717k++ + ++j
18illegalk+++++j
19illegal3 = 4
20false3 == 4
21illegalby = k
2210by = (byte)k
236k = (int)j
2410.0f = k
25illegalk = f
263k = (int)f
273.9000000953674316d = f
28illegalf = d
296.199999809265137f = (float)d
30illegalf = 2.0
312000.0f = 2.0e3F
321by = 1
33illegalk > j > 3
34illegalk > j && > 3
35truek > j && k > 3
365k = j = 5
375k = (j = 5)
38illegal(k = j) = 5
3911k += 1
4020k *= 2
415k /= 2
4210k = (k>j)?k:j+1
43113 % 2
4422k++ + ++k
453k = (int)f
46-1(k%2==0)?-1:1
47false(int)(f + 0.5) == (int)d
48true22 == 22.0
49false(0.1 + 0.1 + 0.1) == 0.3
505.551115123125783E-17(0.1 + 0.1 + 0.1) - 0.3
Copyleft 2003 Fred Swartz MIT License, Last update: 2000-04-10
Advertisement


DMCA.com