ืฉืืขืืจ ืืชืืืืงื ื-Java ืืืื ืืจืื ืคืื ืงืฆืืืช ืืชืืืืืช. ืคืื ืงืฆืืืช ืืจืืืื ืืืืจืืืช ืื ืืื ืืคืื ืงืฆืืืช ืืืฉืืืืช ืืืืชืจ ืืชืื ืืช. ืืืช ืืืคืื ืงืฆืืืช ืืืื ืืื Math.cos() .
ืืจืืืื ืืืืจืื ืืชืื ืืช?
ืืืืื, ืืฉื ื ืืชืื ืชืื ืฉืืืขื ืืื ื ืชืงืืื ืืคืื ืงืฆืืืช ืืจืืืื ืืืืจืืืช ืืขืืืืชื, ืื ืขื ืืืช, ืขืืืจ ืืฉืืืืช ืจืืืช, ืืคืื ืงืฆืืืช ืืืื ืืฉืืืืช ืืืืชืจ. ืืืืืื, ืขืืืจ ืืจืคืืงื ืืืืืฉืืช ืื ืืืืืงื ืฉื ืืฉืืง. ืืืืืื, ืกืื ืืกืื ืืงืืกืื ืืกืื ืืขืืจืืื ืืืืจืืฆืช ืืกืืืื ืฉืื ืืชื ืืืื ืืืฉืชืืฉ ืืื ืืกืืื ืืืืืืงืืื ืืขืืืืืช. ืืื ืืชื ืฆืจืื ืืืฉื ืืช ืืืจื ืื ืชืื ืืืืจื ืืืคื, ืคืื ืงืฆืืืช ืืจืืืื ืืืืจืืืช ืืืืืืช ืืืืืช ืฉืืืืฉืืืช.ืฉืืืช Math.cos() ื-Java
ืืฉืืื ืืืคืืื cos (ืืคืื x) ืฉื ืืืืืงื Math ืืืืืจื ืืช ืขืจื ืืงืืกืื ืืก ืฉื ื- x , ืืืฉืจ x ืืื ืืจืืืื ื, ืืืืืช ืืจืืืื ืื . ืื ื ืืฆืืจื ืขื ืฉืืืช Java.lang.Math.cos() :double cos(double x)
ืื ืื ื ืื ืื ืืืืฉืื ืืืืืืช ืืจืืืื ืื, ืชืืื ืืืฉืชืืฉ ืืคืื ืงืฆืื ืืืืืืืช ืืืืจืช ืจืืืื ืื ืืืขืืืช:
double toDegrees(double angRad)
ืืฉื ื ืื ืคืื ืงืฆืื ืืคืืื ืืืืืจื ืืขืืืช ืืจืืืื ืื, ืฉืื ืืื ืืืืื ืืืืืช ืฉืืืืฉืืช.
double toRadians(double angDeg)
ืื ื ืืืืื ืืงืื ืฉื java.lang.Math.cos() :
public class CosExample {
public static void main(String[] args) {
int x1 = 1;
double x2 = 0.5;
double x3 = Math.PI;
//using java.lang.Math.cos() for 1, 0.5 and PI rad
System.out.println("cosine of " + x1 + " rads = " + Math.cos(x1));
System.out.println("cosine of " + x2 + " rads = " + Math.cos(0));
System.out.println("cosine " + x3 + " rads = " + Math.exp(x3));
//here we declare an 60 degrees angle
double degree = 60;
//here we use Math.toRadians to convert 60 degrees to radians, use the cos() method
//to calculate the cosine of 60 degrees angle and print the result out
System.out.println("cosine of " + degree + " degrees = " + Math.cos(Math.toRadians(degree)));
}
}
ืืคืื ืืื:
ืงืืกืื ืืก ืฉื 1 ืจืื = 0.5403023058681398 ืงืืกืื ืืก ืฉื 0.5 ืจืื = 1.0 ืงืืกืื ืืก 3.141592653589793 ืจืื = 23.140692632779267 ืงืืกืื ืืก ืฉื 600.00000 =00.00000
ืืื ืืงืจืื ืืืืืืื
ืืืชืืืืงื ืืฉ ืืืฉืืื ืฉื ืฆืืจื ืืืชื ืืืืืจืช, ืืื ืกืืฃ ืืืืื ืืฉืืืื. ืืกืคืจ ืืืงื 0.0 ื ืืชื ืืื ืกืืฃ, ืืืืื ืื ืฉืืืื ืืืชืื ืืืืืืืืช ืื ืืฉืืืืืืช ืฉื ืืืชื ืืกืคืจ. ืืชื ืืืื ืืงืื ืฆืืจื ืืืชื ืืืืืจืช ืืืจืืื ืฉืื ืืช. ืืืืืื, ืื ืชื ืกื ืืืืง ืืคืก ืืืคืก ืื ืืื ืกืืฃ ืืืื ืกืืฃ. ื-Java ืืฉ ืงืืืขืื ืืืืืืื ื-class Double ืืื Double.NaN (ืื ืืกืคืจ, ืืคืฉืจ ืืืืจ ืฉืื ืกืื ืฉื ืฆืืจื ืืืชื ืืืืืจืช), Double.POSITIVE_INFINITY ื-Double.NEGATIVE_INFINITY. ืฉืืืช Math.cos() ืืชื ืืืช ืืฆืืจื ืกืคืฆืืคืืช ืืืฉืจ ืืื ืืชืืืืืช ืขื ืฉืืืฉืช ืืืืฉืืื ืืืื. ืื ืืืจืืืื ื ืืื NaN ืื ืืื ืกืืฃ, ืื Math.cos() ืืื NaN. ืืื ื ืืื ืืืืื ืืงืื:public class CosSpecialCases {
public static void main(String[] args) {
double positiveInfinity = Double.POSITIVE_INFINITY;
double negativeInfinity = Double.NEGATIVE_INFINITY;
double nan = Double.NaN;
//The argument is positive infinity, the output is NaN
System.out.println(Math.cos(positiveInfinity));
//The argument is negative infinity, the output NaN
System.out.println(Math.cos(negativeInfinity));
//The argument is NaN, the output is NaN
System.out.println(Math.cos(nan));
}
}
ืืคืื ืืื:
NaN NaN NaN
ืืฉืืืช ืกืื ืืก ืืงืืกืื ืืก ืืืชืืืืื
ื ืกื ืืชืื ืช ืืช ืชื ืืขืช ืืืืื ืืฉืขืื ืืืืฆืขืืช Math.cos() ื- Math.sin() . ืืชื ืืืื ืื ืืฆืจืฃ ืืจืคืืงื (ืืืืฆืขืืช Processing, JavaFX ืื ืืฉืื ืืืจ) ืืืฉืืื ืืื ืืชืงืื ืฉืขืื ืืื ืคืฉ.
ืงืจืืื ื ืืกืคืช: |
---|
GO TO FULL VERSION