![]() |
||
![]() |
![]() Alden Hosting provides professional, efficient, and reliable business-class Web hosting services to small- and medium-sized businesses. |
|
|
JAVA, JSP, SERVLETS, TOMCAT, SERVLETS MANAGER, |
||||||||||||||||||||||||||||||||||||||||||||||||||
| Method | Description |
|---|---|
double abs(double d)
|
Returns the absolute value of the argument. |
double ceil(double d)
|
Returns the smallest integer that is greater than or equal to the argument. Returned as a double. |
double floor(double d)
|
Returns the largest integer that is less than or equal to the argument. Returned as a double. |
double rint(double d)
|
Returns the integer that is closest in value to the argument. Returned as a double. |
long round(double d)
|
Returns the closest long or int, as indicated by the method's return type, to the argument. |
double min(double arg1, double arg2)
|
Returns the smaller of the two arguments. |
double max(double arg1, double arg2)
|
Returns the larger of the two arguments. |
The following program,
BasicMathDemo
, illustrates how to use some of these methods:
public class BasicMathDemo {
public static void main(String[] args) {
double a = -191.635;
double b = 43.74;
int c = 16, d = 45;
System.out.printf("The absolute value of %.3f is %.3f%n", a, Math.abs(a));
System.out.printf("The ceiling of %.2f is %.0f%n", b, Math.ceil(b));
System.out.printf("The floor of %.2f is %.0f%n", b, Math.floor(b));
System.out.printf("The rint of %.2f is %.0f%n", b, Math.rint(b));
System.out.printf("The max of %d and %d is %d%n",c, d, Math.max(c, d));
System.out.printf("The min of of %d and %d is %d%n",c, d, Math.min(c, d));
}
}
Here's the output from this program:
The absolute value of -191.635 is 191.635 The ceiling of 43.74 is 44 The floor of 43.74 is 43 The rint of 43.74 is 44 The max of 16 and 45 is 45 The min of 16 and 45 is 16
Math class.
| Method | Description |
|---|---|
double exp(double d)
|
Returns the base of the natural logarithms, e, to the power of the argument. |
double log(double d)
|
Returns the natural logarithm of the argument. |
double pow(double base, double exponent)
|
Returns the value of the first argument raised to the power of the second argument. |
double sqrt(double d)
|
Returns the square root of the argument. |
The following program,
ExponentialDemo
, displays the value of e, then calls each of the methods listed in the previous table on arbitrarily chosen numbers:
public class ExponentialDemo {
public static void main(String[] args) {
double x = 11.635;
double y = 2.76;
System.out.printf("The value of e is %.4f%n", Math.E);
System.out.printf("exp(%.3f) is %.3f%n", x, Math.exp(x));
System.out.printf("log(%.3f) is %.3f%n", x, Math.log(x));
System.out.printf("pow(%.3f, %.3f) is %.3f%n", x, y, Math.pow(x, y));
System.out.printf("sqrt(%.3f) is %.3f%n", x, Math.sqrt(x));
}
}
Here's the output you'll see when you run ExponentialDemo:
The value of e is 2.7183 exp(11.635) is 112983.831 log(11.635) is 2.454 pow(11.635, 2.760) is 874.008 sqrt(11.635) is 3.411
Math class also provides a collection of trigonometric
functions, which are summarized in the following table.
The value passed into each of these methods is an angle expressed in
radians. You can use the toRadians method
to convert from degrees to radians.
| Method | Description |
|---|---|
double sin(double d)
|
Returns the sine of the specified double value. |
double cos(double d)
|
Returns the cosine of the specified double value. |
double tan(double d)
|
Returns the tangent of the specified double value. |
double asin(double d)
|
Returns the arcsine of the specified double value. |
double acos(double d)
|
Returns the arccosine of the specified double value. |
double atan(double d)
|
Returns the arctangent of the specified double value. |
double atan2(double y, double x)
|
Converts rectangular coordinates (x, y) to polar coordinate
(r, theta) and returns theta.
|
double toDegrees(double d)
|
Converts the argument to degrees or radians. |
Here's a program,
TrigonometricDemo
, that uses each of these methods to compute various trigonometric values for a 45-degree angle:
public class TrigonometricDemo {
public static void main(String[] args) {
double degrees = 45.0;
double radians = Math.toRadians(degrees);
System.out.format("The value of pi is %.4f%n", Math.PI);
System.out.format("The sine of %.1f degrees is %.4f%n", degrees,
Math.sin(radians));
System.out.format("The cosine of %.1f degrees is %.4f%n", degrees,
Math.cos(radians));
System.out.format("The tangent of %.1f degrees is %.4f%n", degrees,
Math.tan(radians));
System.out.format("The arcsine of %.4f is %.4f degrees %n",
Math.sin(radians),
Math.toDegrees(Math.asin(Math.sin(radians))));
System.out.format("The arccosine of %.4f is %.4f degrees %n",
Math.cos(radians),
Math.toDegrees(Math.acos(Math.cos(radians))));
System.out.format("The arctangent of %.4f is %.4f degrees %n",
Math.tan(radians),
Math.toDegrees(Math.atan(Math.tan(radians))));
}
}
The output of this program is as follows:
The value of pi is 3.1416 The sine of 45.0 degrees is 0.7071 The cosine of 45.0 degrees is 0.7071 The tangent of 45.0 degrees is 1.0000 The arcsine of 0.7071 is 45.0000 degrees The arccosine of 0.7071 is 45.0000 degrees The arctangent of 1.0000 is 45.0000 degrees
random() method returns a pseudo-randomly selected number between 0.0 and 1.0.
The range includes 0.0 but not 1.0. In other words: 0.0 <= Math.random() < 1.0.
To get a number in a different range, you can perform arithmetic on the value returned by the random
method. For example, to generate an integer between 0 and 9, you would write:
By multiplying the value by 10, the range of possible values becomesint number = (int)(Math.random() * 10);
0.0
<= number < 10.0.
Using Math.random works well when you need to generate a single random
number. If you need to generate a series of random numbers,
you should create an instance of java.util.Random
and invoke methods on that object to generate numbers.
Alden Hosting offers private JVM (Java Virtual Machine), Java Server Pages (JSP), Servlets, and Servlets Manager with our Web Hosting Plans WEB 4 PLAN and WEB 5 PLAN , WEB 6 PLAN .
At Alden Hosting we eat and breathe Java! We are the industry leader in providing affordable, quality and efficient Java web hosting in the shared hosting marketplace. All our sites run on our Java hosing platform configured for optimum performance using Java 1.6, Tomcat 6.0.X, MySQL 5.0.x, Apache 2.2.xx and web application frameworks such as Struts, Hibernate, Cocoon, Ant, etc.
We offer only one type of Java hosting - Private Tomcat. Hosting accounts on the Private Tomcat environment get their very own Tomcat server. You can start and re-start your entire Tomcat server yourself.
![]() |
|
http://alden-servlet-Hosting.com
JSP at alden-servlet-Hosting.com
Servlets at alden-servlet-Hosting.com
Servlet at alden-servlet-Hosting.com
Tomcat at alden-servlet-Hosting.com
MySQL at alden-servlet-Hosting.com
Java at alden-servlet-Hosting.com
sFTP at alden-servlet-Hosting.com
http://alden-tomcat-Hosting.com
JSP at alden-tomcat-Hosting.com
Servlets at alden-tomcat-Hosting.com
Servlet at alden-tomcat-Hosting.com
Tomcat at alden-tomcat-Hosting.com
MySQL at alden-tomcat-Hosting.com
Java at alden-tomcat-Hosting.com
sFTP at alden-tomcat-Hosting.com
http://alden-sftp-Hosting.com
JSP at alden-sftp-Hosting.com
Servlets at alden-sftp-Hosting.com
Servlet at alden-sftp-Hosting.com
Tomcat at alden-sftp-Hosting.com
MySQL at alden-sftp-Hosting.com
Java at alden-sftp-Hosting.com
sFTP at alden-sftp-Hosting.com
http://alden-jsp-Hosting.com
JSP at alden-jsp-Hosting.com
Servlets at alden-jsp-Hosting.com
Servlet at alden-jsp-Hosting.com
Tomcat at alden-jsp-Hosting.com
MySQL at alden-jsp-Hosting.com
Java at alden-jsp-Hosting.com
sFTP at alden-jsp-Hosting.com
http://alden-java-Hosting.com
JSp at alden-java-Hosting.com
Servlets at alden-java-Hosting.com
Servlet at alden-java-Hosting.com
Tomcat at alden-java-Hosting.com
MySQL at alden-java-Hosting.com
Java at alden-java-Hosting.com
sFTP at alden-java-Hosting.com
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP at JSP.aldenWEBhosting.com
Servlets at servlets.aldenWEBhosting.com
Tomcat at Tomcat.aldenWEBhosting.com
mysql at mysql.aldenWEBhosting.com
Java at Java.aldenWEBhosting.com
Web Hosts Portal
Web Links
Web Links
Web Hosting
JSP Solutions Web Links
JSP Solutions Web Hosting
Servlets Solutions Web Links
Servlets Solutions Web Hosting
Web Links
Web Links
.
.
.
.
.
.
.
.
.
.
jsp hosting
servlets hosting
web hosting
web sites designed
cheap web hosting
web site hosting
myspace web hosting