Beruflich Dokumente
Kultur Dokumente
- Expressions
Lecture
CECSD B Slide 2 of 69.
Arithmetic Operators
Lecture
CECSD B Slide 3 of 69.
Pounds to Kg conversion
Lecture
CECSD B Slide 4 of 69.
Pounds to Kg conversion 2
Lecture
CECSD B Slide 5 of 69.
Integer Division
• When division is performed on integers (byte, short,
int, long), the result is truncated to an integer.
int j = 5;
double x = 5.0, y;
System.out.println(j / 2); // 2
System.out.println(x / 2.0); // 2.5
System.out.println(5 / 2); // 2
y = j / 2 ; // 2
Lecture
CECSD B Slide 6 of 69.
Complex Expressions
Lecture
CECSD B Slide 7 of 69.
Operator Precedence
Lecture
CECSD B Slide 8 of 69.
Operator Precedence Examples
Expression Result
10 - 7 - 1 2
10 - (7 - 1) 4
1 + 2 * 3 7
(1 + 2) * 3 9
1 - 2 * 3 + 4 * 5 15
Lecture
CECSD B Slide 9 of 69.
Conversions
Lecture
CECSD B Slide 10 of 69.
Conversion Examples
double f, x;
int j;
f = 5;
f = 5.0 / 2;
f = x * j;
f = 5 / 2;
f = (float) j / 5;
j = (int) f;
j = (int) 5.0 / 2.0;
Lecture
CECSD B Slide 11 of 69.