> Java > java지도 시간 > 본문

Java의 수학 함수

WBOY
풀어 주다: 2024-08-30 15:33:09
원래의
938명이 탐색했습니다.

Java는 가장 유용한 프로그래밍 언어 중 하나입니다. 아키텍처 구축, 과학 계산 해결, 지도 구축 등과 같은 다양한 애플리케이션이 있습니다. 이러한 작업을 쉽게 하기 위해 Java는 제곱, 지수 등 여러 연산을 수행하는 java.lang.Math 클래스 또는 Java의 수학 함수를 제공합니다. , 천장, 로그, 입방체, 절대값, 삼각법, 제곱근, 바닥 등

광고 이 카테고리에서 인기 있는 강좌 JAVA MASTERY - 전문 분야 | 78 코스 시리즈 | 15가지 모의고사

무료 소프트웨어 개발 과정 시작

웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등

이 수업은 수학 수업의 기본이 되는 두 가지 분야를 제공합니다. 그들은

  • 자연로그의 밑이 되는 'e'(718281828459045)
  • 원의 지름에 대한 둘레의 비율인 '파이'(141592653589793)

Java의 다양한 수학 함수

Java는 다양한 수학 메소드를 제공합니다. 아래와 같이 분류할 수 있습니다.

  • 기본 수학 방법
  • 삼각수학법
  • 대수 수학 방법
  • 쌍곡선 수학 방법
  • 각수학 방법

자세히 알아보겠습니다.

1. 기본 수학 방법

더 나은 이해를 위해 아래와 같이 Java 프로그램에서 위 메소드를 구현할 수 있습니다.

방법 반환값 인수

복근()

인수의 절대값. 즉, 양수 값 long, int, float, double

int n1 = Math.abs(80)  //n1=80

int n2 =Math.abs (-60) //n2=60

sqrt()

인수의 제곱근 더블

double n= Math.sqrt (36.0) // n=6.0

cbrt()

인수의 세제곱근 더블

double n= Math.cbrt (8.0) // n=2.0

최대()

인수에 전달된 두 값의 최대값 long, int, float, double

int n=Math.max(15,80) //n=80

분()

인수에 전달된 두 값의 최소값 long, int, float, double

int n=Math.min(15,80) //n=15

셀()

float 값을 정수 값으로 반올림합니다 더블 더블 n=Math.ceil(6.34) //n=7.0
바닥() float 값을 정수 값으로 내림 더블

더블 n=Math.floor(6.34) //n=6.0

라운드()

float 또는 double 값을 위 또는 아래로 정수 값으로 반올림합니다 더블, 플로트 double n = Math.round(22.445);//n=22.0 double n2 = Math.round(22.545); //n=23.0

펑()

첫 번째 매개변수의 값을 두 번째 매개변수로 올립니다

더블

더블 n= Math.pow(2.0, 3.0) //n=8.0

무작위()

0과 1 사이의 임의의 숫자 더블 이중 n= Math.random() //n= 0.2594036953954201

시그넘()

전달된 매개변수의 부호.

긍정적이면 1이 표시됩니다.

음수인 경우 -1이 표시됩니다.

0이면 0이 표시됩니다

더블, 플로트

더블 n = 수학. 부호(22.4);//n=1.0 double n2 = 수학. 시그넘(-22.5);//n=-1.0

추가Exact()

매개변수의 합입니다. 얻은 결과가 long 또는 int 값을 오버플로하는 경우 예외가 발생합니다. 정수, 길이

int n= Math.addExact(35, 21)//n=56

incrementExact()

1씩 증가하는 매개변수입니다. 얻은 결과가 int 값을 오버플로하는 경우 예외가 발생합니다. 정수, 길이

int n=수학. incrementExact(36) //n=37

빼기Exact()

매개변수의 차이. 얻은 결과가 int 값을 오버플로하는 경우 예외가 발생합니다. 정수, 길이

int n= Math.subtractExact(36, 11) //n=25

곱셈정확()

매개변수의 합입니다. 얻은 결과가 long 또는 int 값을 오버플로하는 경우 예외가 발생합니다. 정수, 길이

int n= Math.multiplyExact(5, 5) //n=25

decrementExact()

매개변수가 1씩 감소합니다. 얻은 결과가 int 또는 long 값을 오버플로하는 경우 예외가 발생합니다. 정수, 길이

int n=수학. 감소Exact (36) //n=35

negateExact()

매개변수의 부정입니다. 얻은 결과가 int 또는 long 값을 오버플로하는 경우 예외가 발생합니다. 정수, 길이

int n=수학. negateExact(36) //n=-36

복사사인()

첫 번째 매개변수의 절대값과 두 번째 매개변수에 지정된 부호 더블,플로트

double d= Math.copySign(29.3,-17.0) //n=-29.3

floorDiv()

첫 번째 매개변수를 두 번째 매개변수로 나누어 바닥 연산을 수행합니다. 긴 정수

int n= Math.floorDiv(25, 3) //n=8

하이팟()

매개변수의 제곱의 합을 계산하고 제곱근 연산을 수행합니다. 중간 오버플로나 언더플로가 있어서는 안 됩니다. 더블

double n=Math.hypot(4,3) //n=5.0

getExComponent()

편향되지 않은 지수. 이 지수는 double 또는 float로 표시됩니다 정수

더블 n=Math.getExComponent(50.45) //n=5

코드:

//Java program to implement basic math functions
public class JavaMathFunctions {
public static void main(String[] args) {
int n1 = Math.abs(80);
System.out.println("absolute value of 80 is: "+n1);
int n2 = Math.abs(-60);
System.out.println("absolute value of -60 is: "+n2);
double n3 = Math.sqrt(36.0);
System.out.println("Square root of 36.0 is: "+n3);
double n4 = Math.cbrt(8.0);
System.out.println("cube root 0f 8.0 is: "+n4);
int n5= Math.max(15,80);
System.out.println("max value is: "+n5);
int n6 =Math.min(15,80);
System.out.println("min value is: "+n6);
double n7 = Math.ceil(6.34);
System.out.println("ceil value of 6.34 is "+n7);
double n8 = Math.floor(6.34);
System.out.println("floor value of 6.34 is: "+n8);
double n9 = Math.round(22.445);
System.out.println("round value of 22.445 is: "+n9);
double n10 = Math.round(22.545);
System.out.println("round value of 22.545 is: "+n10);
double n11= Math.pow(2.0, 3.0);
System.out.println("power value is: "+n11);
double n12= Math.random();
System.out.println("random value is: "+n12);
double n13 = Math. signum (22.4);
System.out.println("signum value of 22.4 is: "+n13);
double n14 = Math. signum (-22.5);
System.out.println("signum value of 22.5 is: "+n14);
int n15= Math.addExact(35, 21);
System.out.println("added value is: "+n15);
int n16=Math. incrementExact(36);
System.out.println("increment of 36 is: "+n16);
int n17 = Math.subtractExact(36, 11);
System.out.println("difference is: "+n17);
int n18 = Math.multiplyExact(5, 5);
System.out.println("product is: "+n18);
int n19 =Math. decrementExact (36);
System.out.println("decrement of 36 is: "+n19);
int n20 =Math. negateExact(36);
System.out.println("negation value of 36 is: "+n20);
}
}
로그인 후 복사

출력:

Java의 수학 함수

2. 삼각수학법

다음은 표에 언급된 삼각 수학 함수를 구현하는 Java 프로그램입니다.

Method

Return value Arguments Example

sin()

Sine value of the parameter double

double num1 = 60; //Conversion of value to radians

double value = Math.toRadians(num1); print Math.sine (value) //output is 0.8660254037844386

cos()

Cosine value of the parameter double

double num1 = 60; //Conversion of value to radians

double value = Math.toRadians(num1); print Math.cos (value) //output is           0.5000000000000001

tan()

tangent value of the parameter double

double num1 = 60; //Conversion of value to radians

double value = Math.toRadians(num1); print Math.tan(value) //output is 1.7320508075688767

asin()

Arc Sine value of the parameter. Or Inverse sine value of the parameter double

Math.asin(1.0) // 1.5707963267948966

acos()

Arc cosine value of the parameter Or Inverse Cosine value of the parameter double

Math.acos(1.0) //0.0

atan()

Arctangent value of the parameter Or Inverse tangent value of the parameter double

Math.atan(6.267) // 1.4125642791467878

방법 반환 값 인수 예

sin()

매개변수의 사인 값 더블

더블 num1 = 60; //값을 라디안으로 변환

double value = Math.toRadians(num1); print Math.sine(값) //출력은 0.8660254037844386

cos()

매개변수의 코사인 값 더블

더블 num1 = 60; //값을 라디안으로 변환

double value = Math.toRadians(num1); print Math.cos(값) //출력은           0.5000000000000001

tan()

매개변수의 탄젠트 값 더블

더블 num1 = 60; //값을 라디안으로 변환

double value = Math.toRadians(num1); print Math.tan(value) //출력은 1.7320508075688767

asin()

매개변수의 Arc Sine 값입니다. 또는 매개변수의 역사인 값 더블

Math.asin(1.0) // 1.5707963267948966

acos()

매개변수의 아크코사인 값 또는 매개변수의 역코사인 값 더블

Math.acos(1.0) //0.0

atan()

매개변수의 아크탄젠트 값 또는 매개변수의 역탄젠트 값 더블

Math.atan(6.267) // 1.4125642791467878

Code:

//Java program to implement trigonometric math functions
public class JavaMathFunctions {
public static void main(String[] args) {
double num1 = 60;
// Conversion of value to radians
double value = Math.toRadians(num1);
System.out.println("sine value is : "+Math.sin(value));
System.out.println("cosine value is : "+Math.cos(value));
System.out.println("tangent value is : "+Math.tan(value));
double num2 = 1.0;
System.out.println("acosine value is : "+Math.acos(num2));
System.out.println("asine value is : "+Math.asin(num2));
double num3 = 6.267;
System.out.println("atangent value is : "+Math.atan(num3)); <strong>Output:</strong>
로그인 후 복사

Java의 수학 함수

3. Logarithmic Math Methods

Following is the sample program that implements Logarithmic math methods:

Method

Return Value Arguments

Example

expm1()

Calculate E’s power and minus 1 from it. E is Euler’s number. So here, it is ex-1. double

double n = Math.expm1(2.0) // n = 6.38905609893065

exp()

E’s power to the given parameter. That is, ex double

double n=Math.exp(2.0) //n = 7.38905609893065

log()

Natural logarithm of parameter double

double n=Math.log(38.9) //n=3.6609942506244004

log10()

Base 10 logarithm of parameter double

double n =  Math.log10(38.9) //n= 1.5899496013257077

log1p()

Natural logarithm of the sum of parameter and one. ln(x+1) double

double n =   Math.log1p(26) //n= 3.295836866004329

Code:

//Java program to implement logarithmic math functions
public class JavaMathFunctions {
public static void main(String[] args) {
double n1 = Math.expm1(2.0);
double n2 = Math.exp(2.0);
double n3 = Math.log(38.9);
double n4 = Math.log10(38.9);
double n5 = Math.log1p(26);
System.out.println("expm1 value of 2.0 is : "+n1);
System.out.println("exp value of 2.0 is : "+n2);
System.out.println("log of 38.9 is : "+n3);
System.out.println("log10 of 38.9 is : "+n4);
System.out.println("log1p of 26 is : "+n5);
}}
로그인 후 복사

Output:

Java의 수학 함수

4. Hyperbolic Math Methods

Following is the Java program to implement hyperbolic math functions mentioned in the table:

Method

Return value Arguments

Example

sinh()

Hyperbolic Sine value of the parameter. i.e (ex – e -x)/2 Here, E is the Euler’s number. double

double num1=Math.sinh (30) //output is 5.343237290762231E12

cosh()

Hyperbolic Cosine value of the parameter. i.e. (ex + e -x)/2 Here, E is the Euler’s number. double

double num1 = Math.cosh (60.0) //output is 5.710036949078421E25

tanh()

Hyperbolic tangent value of the parameter double

double num1= Math.tanh (60.0) //output is 1.0

Code:

//Java program to implement HYPERBOLIC math functions
public class JavaMathFunctions {
public static void main(String[] args) {
double n1 = Math.sinh (30);
double n2 = Math.cosh (60.0);
double n3 = Math.tanh (60.0);
System.out.println("Hyperbolic sine value of 300 is : "+n1);
System.out.println("Hyperbolic cosine value of 60.0 is : "+n2);
System.out.println("Hyperbolic tangent value of 60.0 is : "+n3);
}
}
로그인 후 복사

Output:

Java의 수학 함수

5. Angular Math Methods

Method Return Value Arguments Example
toRadians() Degree angle converts to radian angle double

double n = Math.toRadians(180.0) //n= 3.141592653589793

toDegrees() Radian angle converts to Degree angle double

double n = Math. toDegrees (Math.PI) //n=180.0

 Now, let us see a sample program to demonstrate Angular Math methods.

Code:

//Java program to implement Angular math functions
public class JavaMathFunctions {
public static void main(String[] args) {
double n1 = Math.toRadians(180.0);
double n2 = Math. toDegrees (Math.PI);
System.out.println("Radian value of 180.0 is : "+n1);
System.out.println("Degree value of pi is : "+n2);
}
}
로그인 후 복사

Output:

Java의 수학 함수

Conclusion

Java offers a wide variety of math functions to perform different tasks such as scientific calculations, architecture designing, structure designing, building maps, etc. This document discusses several basic, trigonometric, logarithmic and angular math functions in detail with sample programs and examples.

위 내용은 Java의 수학 함수의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!