70 likes | 166 Views
Learn about Java's numeric data types, arithmetic expressions, assignment operators, precedence rules, and constants like PI and mathematical functions in the Math class.
E N D
Numeric Data Types • There are six numeric data types: byte, short, int, long, float, and double.
This is an integer division where the fractional part is truncated. Arithmetic Operators • The following table summarizes the arithmetic operators available in Java. • ++ and -- for integer type variables
Arithmetic Expressions • Examples: sum = firstNumber + secondNumber; avg = (one + two + three) / 3.0; total++; • Assignment operators • Tral-la-la, out to reality … NumericOperators.java
Example Program Flonk … out to reality … NumericPrecedence.java
The reserved word final is used to declare constants. These are constants, also called named constant. These are called literal constant. 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;
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