Math & Number Operations Code Samples
Learn how to use numbers and math operations in applications written in the Java programming language.
- BasicMathDemo.java illustrates how to get the absolute value, ceiling value, floor value, and relative integer value. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- DecimalFormatDemo.java formats decimal numbers into strings. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- ExponentialDemo.java displays the exponent value and calls the exp, log, pow, and sqrt methods on it. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- MinDemo.java finds the smaller of two values. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- NumberDemo.java creates two Float objects and one Double object. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- Numbers.java shows you how to perform various math operations on numbers received from the command line. For supporting information see New to Java Programming Supplement, October 2001.
- RandomBagDemo.java generates random numbers. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- ScoresAverage.java shows you how to store numbers in an array and compute the average. For supporting information see New to Java Programming Supplement, August 2001.
- ToStringDemo.java uses the toString method to convert a number to a string, and uses some string methods to compute the number of digits before and after the decimal point. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- TrigonometricDemo.java computes various trigonometric values for a 45-degree angle. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- ValueOfDemo.java gets two strings from the command line, converts them to numbers, and performs arithmetic operations on the value. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.