Theory Part 2 PDF
Theory Part 2 PDF
FUNCTION
The Java.Math class contains a set of trigonometric functions. These functions can
calculate values used in trigonometry. like sine, cosine, tangent etc. I will cover the most
used trigonometry functions in the following sections. If you are looking for a trigonometric
function and you cannot find it here, check the JavaDoc for the Java.Math class. The Math
class just might have the function you are looking for, even if I have not described it here.
1. Math.PI
The Math.PI constant is a double with a value that is very close to the value of PI - the
mathematical definition of PI. You will often need the Math.PI field when making
trigonometric calculations.
Example program
import java.lang.Math.*;
public class Pie {
public static void main(String[] args) {
//radius and length
double radius = 5;
double len = 15;
// calculate the area using PI
double area = radius * radius * Math.PI;
//and now volume
double volume = area * len;
System.out.println("Volume of cylinder is: " + volume);
}
}
2. Math.sin()
The Math.sin() method calculates the sine value of some angle value in radians. Here is a
Java Math.sin() example:
Alternative method
class sinTable
{
public static void main(String ss [])
{
int i;
double x,y;
for(i=0;i<=90:i++)
{
x=Math .to Radians(1);
y=Math. sin(x);
System.out.println(x+"\t"+y);
}
}
}