Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numeric Data Types There are six numeric data types: byte, short, int, long, float, and double.

Similar presentations


Presentation on theme: "Numeric Data Types There are six numeric data types: byte, short, int, long, float, and double."— Presentation transcript:

1 Numeric Data Types There are six numeric data types: byte, short, int, long, float, and double.

2 Arithmetic Operators The following table summarizes the arithmetic operators available in Java. ++ and -- for integer type variables This is an integer division where the fractional part is truncated.

3 Arithmetic Expressions Examples: sum = firstNumber + secondNumber; avg = (one + two + three) / 3.0; total++; Assignment operators Tral-la-la, out to reality … NumericOperators.java

4 Precedence Rules

5 Example Program Flonk … out to reality … NumericPrecedence.java

6 Constants We can change the value of a variable. If we want the value to remain the same, we use a constant. final double PI = 3.14159; final int MONTH_IN_YEAR = 12; final short FARADAY_CONSTANT = 23060; These are constants, also called named constant. The reserved word final is used to declare constants. These are called literal constant.

7 The Math Class The Math class in the java.lang package includes many common and useful mathematical functions such sin, cos, tan, square root, exponentiation, and others. The mathematical formula is expressed in Java as Math.abs( Math.sin( Math.PI / 4.0) * x ) Splodge … out to reality … MathFunctions.java


Download ppt "Numeric Data Types There are six numeric data types: byte, short, int, long, float, and double."

Similar presentations


Ads by Google