Consider a floating-point number such as 12.155. This number is between integer 12 and integer
13:
In the same way, consider a number such as –24.06. As this number is
negative, it is between –24 and –25, with –24 being greater.
In arithmetic, the ceiling of a number is the closest integer that is
greater or higher than the number considered. In the first case, the
ceiling of 12.155 is 13 because 13 is the closest integer greater than
or equal to 12.155. The ceiling of –24.06 is –24.
To support the finding of a ceiling, the Math class is equipped with a method
named ceil. Its syntax is:
static double ceil(double a);
This method takes as argument a floating-point number of variable whose ceiling
needs to be found. Here is an example:
import java.lang.Math; public class Exercise { public static void main(String[] args) { double value1 = 155.55; double value2 = -24.06; System.out.println("The ceiling of " + value1 + " is " + Math.ceil(value1)); System.out.println("The ceiling of " + value2 + " is " + Math.ceil(value2)); } }
This would produce:
The ceiling of 155.55 is 156.0 The ceiling of -24.06 is -24.0
Consider two floating numbers such as 128.44 and -36.72. The number
128.44 is between 128 and 129 with 128 being the lower. The number
–36.72 is between –37 and –36 with –37 being the lower. The lowest but
closest integer value of a number is referred to as its floor.
To assist you with finding the floor of a number, the Math class provides the floor()
method. Its syntax is:
static double floor(double d);
The floor() method takes the considered value as the argument and returns
a decimal number that is less than or equal to argument. Here is an example:
import java.lang.Math; public class Exercise { public static void main(String[] args) { double value1 = 1540.25; double value2 = -360.04; System.out.println("The floor of " + value1 + " is " + Math.floor(value1)); System.out.println("The floor of " + value2 + " is " + Math.floor(value2)); } }
This would produce:
The floor of 1540.25 is 1540.0 The floor of -360.04 is -361.0
The power is the value of one number or expression raised to another number. This follows the formula:
ReturnValue = xy
To support this operation, the Math class is equipped with a
method named pow whose syntax is:
static double pow(double x, double y);
This method takes two arguments. The first argument,
x, is used as the base number to be evaluated. The second argument, y,
also called the exponent, will raise x to this value.
Here is an example:
import java.lang.Math;
public class Exercise {
public static void main(String[] args) {
final double source = 25.38;
final double exp = 3.12;
double result = Math.pow(source, exp);
System.out.println("Pow(" + source + ", " + exp + ") = " + result);
}
}
This would produce:
Pow(25.38, 3.12) = 24099.8226934415
You can calculate the exponential value of a number. To support this, the Math
class provides the exp() method. Its syntax is:
static double exp(double d);
Here is an example of calling this method:
import java.lang.Math;
public class Exercise {
public static void main(String[] args) {
System.out.println("The exponential of 709.78222656 is " +
Math.exp(709.78222656));
}
}
This would produce:
The exponential of 709.78222656 is 1.79681906923757E308
If the value of x is less than -708.395996093 (approximately), the
result is reset to 0 and qualifies as underflow. If the value of the
argument x is greater than 709.78222656 (approximately), the result
qualifies as overflow.
To calculate the natural logarithm of a number, you can call
the Math.log() method. Its syntax is:
static double log(double d);
Here is an example:
import java.lang.Math;
public class Exercise {
public static void main(String[] args) {
double log = 12.48D;
System.out.println("Log of " + log + " is " + Math.log(log));
}
}
This would produce:
Log of 12.48 is 2.52412736294128
You can calculate the square root of a decimal positive number. To support this,
the Math class is equipped with a method named sqrt whose syntax is:
static double sqrt(double d);
This method takes one argument as a positive floating-point number. After the calculation, the
method returns the square root of x:
import java.lang.Math;
public class Exercise {
public static void main(String[] args) {
double sqrt = 8025.73D;
System.out.println("The square root of " +
sqrt + " is " + Math.sqrt(sqrt));
}
}
This would produce:
The square root of 8025.73 is 89.5864387058666
A circle is a group or series of distinct points drawn at an exact same
distance from another point referred to as the center. The distance from
the center C to one of these equidistant points is called the radius,
R. The line that connects all of the points that are equidistant to the
center is called the circumference of the circle. The diameter is the
distance between two points of the circumference to the center; in other
words, a diameter is double the radius.
To manage the measurements and other related operations, the
circumference is divided into 360 portions. Each of these portions is
called a degree. The unit used to represent the degree is the degree,
written as ˚. Therefore, a circle contains 360 degrees, that is 360˚.
The measurement of two points A and D of the circumference could have 15
portions of the circumference. In this case, this measurement would be
represents as 15˚.
The distance between two equidistant points A and B is a round shape
geometrically defined as an arc. An
angle is the ratio of the distance between two points A and B of the
circumference divided by the radius R. This can be written as:
Therefore, an angle is the ratio of an arc over the radius. Because an
angle is a ratio and not a “physical” measurement, which means an angle
is not a dimension, it is independent of the size of a circle. Obviously
this angle represents the number of portions included by the three
points. A better unit used to measure an angle is the radian or
rad.
A cycle is a measurement of the rotation around the circle. Since the
rotation is not necessarily complete, depending on the scenario, a
measure is made based on the angle that was covered during the rotation.
A cycle could cover part of the circle in which case the rotation would
not have been completed. A cycle could also cover the whole 360˚ of the
circle and continue there after. A cycle is equivalent to the radian
divided by 2 * Pi.
The word п, also written as Pi, is a constant number used in various
mathematical calculations. Its approximate value is 3.1415926535897932.
The calculator of Windows represents it as
3.1415926535897932384626433832795.
To support the Pi constant, the Math class is equipped with a constant
named PI.
A diameter is two times the radius. In geometry, it is written as 2R. In
C++, it is written as 2 * R or R * 2 (because the multiplication is
symmetric). The circumference of a circle is calculated by multiplying
the diameter to Pi, which is 2Rп, or 2 * R * п or 2 * R * Pi.
A radian is 2Rп/R radians or 2Rп/R rad, which is the same as 2п rad or 2 * Pi
rad.
To perform conversions between the degree and the radian, you can use the formula:
360˚ = 2п rad which is equivalent to 1 rad = 360˚ / 2п = 57.3˚.
Consider the following geometric figure:
Consider AB the length of A to B, also referred to as the hypotenuse.
Also consider AC the length of A to C which is the side adjacent to
point A. The cosine of the angle at point A is the ratio AC/AB. That is,
the ratio of the adjacent length, AC, over the length of the
hypotenuse,
AB:
The returned value, the ratio, is a double-precision number between –1 and 1.
To calculate the cosine of an angle, the Math class
provides the cos() method. Its syntax is:
static double cos(double d);
Here is an example:
import java.lang.Math;
public class Exercise {
public static void main(String[] args) {
int number = 82;
System.out.println("The cosine of " + number + " is " + Math.cos(number));
}
}
This would produce:
The cosine of 82 is 0.949677697882543
Consider AB the length of A to B, also called the hypotenuse to point A.
Also consider CB the length of C to B, which is the opposite side to
point A. The sine represents the ratio of CB/AB; that is, the ratio of
the opposite side, CB over the
hypotenuse AB.
To calculate the sine of a value, you can call the sin()
method of the Math class. Its syntax is:
static double sin(double a);
Here is an example:
import java.lang.Math;
public class Exercise {
public static void main(String[] args) {
double number = 82.55;
System.out.println("The sine of " + number + " is " + Math.sin(number));
}
}
This would produce:
The sine of 82.55 is 0.763419622322519
Consider AC the length of A to C. Also consider BC the length of B to C. The tangent is the result of
BC/AC; that is, the
ratio of BC over AC. To assist you with calculating the tangent of of a number,
the Math class is equipped with a method named tan whose syntax
is:
static double tan(double a);
Here is an example:
import java.lang.Math;
public class Exercise {
public static void main(String[] args) {
int number = 225;
System.out.println("The tangent of " + number + " is " + Math.tan(number));
}
}
This would produce:
The tangent of 225 is -2.5321149923343427
Consider BC the length of B to C. Also consider AC the length of A to C. The arc tangent is the ratio of
BC/AC. To calculate the arc tangent of a value, you can use the Math.atan()
method. Its syntax is
static double atan(double d);
Here is an example:
import java.lang.Math;
public class Exercise {
public static void main(String[] args) {
short number = 225;
System.out.println("The arc tangent of " + number + " is " +
Math.atan(number));
}
}
This would produce:
The arc tangent of 225 is 1.566351911613937 |
Mathematics in Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment