1 / 7

Numeric Data Types

Learn about Java's numeric data types, arithmetic expressions, assignment operators, precedence rules, and constants like PI and mathematical functions in the Math class.

cline
Download Presentation

Numeric Data Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

  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. 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;

  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

More Related