🌐
Princeton CS
introcs.cs.princeton.edu › java › 12types › Trig.java.html
Trig.java
August 11, 2022 - * * % java Trig * sin(30.0) = 0.49999999999999994 * cos(30.0) = 0.8660254037844387 * tan(30.0) = 0.5773502691896257 * 0.49999999999999994 / 0.8660254037844387 = 0.5773502691896256 * 0.24999999999999994 + 0.7500000000000001 = 1.0 * ******************************************************************************/ public class Trig { public static void main(String[] args) { double degrees = Double.parseDouble(args[0]); double radians = Math.toRadians(degrees); double s = Math.sin(radians); System.out.println("sin(" + degrees + ") = " + s); double c = Math.cos(radians); System.out.println("cos(" + degrees + ") = " + c); double t = Math.tan(radians); System.out.println("tan(" + degrees + ") = " + t); System.out.println(s + " / " + c + " = " + s / c); double r = s*s + c*c; System.out.println(s*s + " + " + c*c + " = " + r); } }
🌐
Coderanch
coderanch.com › t › 702651 › java › converting-sin-cos-tan-result
converting a sin/cos/tan result into a degree value (Beginning Java forum at Coderanch)
November 22, 2018 - Taking the sine of it is then taking the sine of the sine, not what you want. If you do take the sine of 0.8, then Java takes this 0.8 to be the angle in radians. The relation between radians and degrees is 2 * Pi radians = 360 degrees So 1 radian is equal (360 / (2 * Pi)) degrees.
Discussions

Trig functions in java
but that introduces a level of inaccuracy because pi is used, being an irrational number. How is PI represented though? It's as an approximated decimal number. The conversion functions in Math.toRadian/toDegree involve a single multiplication. FYI, here is the source code for the [sin function in jdk7.] ( https://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/src/share/native/java/lang/fdlibm/src/k_sin.c ) Any 'inaccuracies' you think are involved will be the limitations of double value type. You could spend a lot of time (and at some point you should) understanding floating point arithmetic and what error gets introduced if and when you add and multiply two numbers. As always though, the lesson to be learned here is to never assume, try it out yourself, test it, benchmark it, profile it. Armchair speculation in Java is about the worst endeavor to be engaged in compared to other languages. More on reddit.com
🌐 r/javahelp
7
1
August 8, 2022
Calculating of PI from sin() function in Java - Mathematics Stack Exchange
So I'm trying to finish my school project with processing and I'm wondering if there is a way to calculate PI from sin() like this. But I don't know how to use sin() function with degrees in Java or how to write my own. The problem with radians is that I need to convert radians into degrees ... More on math.stackexchange.com
🌐 math.stackexchange.com
March 16, 2017
When should I use the angle in radians or in degrees when calculating sine(angle)?
When there is no "°" then you have radians. Radians are just real numbers but we tell that something is in radians when we want tell that we use real numbers as arguments not angles. More on reddit.com
🌐 r/learnmath
12
7
August 23, 2023
How do I, by hand, figure out what Sin(x) is ?
In general: you don't. You should know the values for 0, 30, 45, 60, 90 degrees, since they are relatively easy. One can then get some additional values by the symmetry, half angle formula and addition theorems, but it gets messy fast. More on reddit.com
🌐 r/askmath
107
77
June 17, 2023
🌐
W3Schools
w3schools.com › jsref › jsref_sin.asp
W3Schools.com
Math.sin(x) expect x in radians. To use degrees, convert degrees to radians first.
🌐
Reddit
reddit.com › r/javahelp › trig functions in java
r/javahelp on Reddit: Trig functions in java
August 8, 2022 -

I was experimenting in bluej, and I found that trig functions take in radians as the unit. I know I can convert the answer to degrees, but that introduces a level of inaccuracy because pi is used, being an irrational number. Are there trig functions that have parameters that are measured in degrees and not radians?

🌐
C# Corner
c-sharpcorner.com › article › about-java-math-class
Java Math Class and Methods
June 14, 2023 - This asin() returns the arc sine of an angle in the range of –pi/2 through pi/2. toRadians method converts an angle measured in degrees to the equivalent angle measured in radians.
🌐
Sarthaks eConnect
sarthaks.com › 3497550 › explain-java-math-sin-method
Explain Java Math sin() Method - Sarthaks eConnect | Largest Online Education Community
April 29, 2023 - LIVE Course for free · The Java Math sin() method is a built-in function that calculates the sine of a given angle in radians. The sin() method belongs to the java.lang.Math class and takes a single argument of type double, which represents ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
2 days ago - Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › java › lang › number_sin.htm
Java - Math sin() Method
public class Test { public static void main(String args[]) { float degrees = (float)0.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)); } } This will produce the following result − · The value of pi is 3.1416 The sine of 0.0 degrees is 0.0000 · java_numbers.htm ·
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-asin-method-example
Java Math asin() Method - GeeksforGeeks
May 7, 2025 - // Java program to convert degrees to radians public class Geeks { public static void main(String[] args) { double degrees = 30.0; double radians = Math.toRadians(degrees); System.out.println("asin(sin30°) in radians: " + Math.asin(Math.sin(radians))); } } Output ·
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › toRadians
Java Math toRadians() - Convert Degrees to Radians | Vultr Docs
September 27, 2024 - public static double ... making the code clean and maintainable. The Java Math.toRadians() function efficiently converts angles from degrees to radians, a conversion crucial for applications requiring precise angular ...
🌐
Quizlet
quizlet.com › 361364336 › chapter-4-java-flash-cards
chapter 4 java Flashcards | Quizlet
B. Math.toRadians(30) Explanation: Note that Math.asin returns an angle in radians. Math.sin(Math.PI) returns _______. A. 0.0 B. 1.0 C. 0.5 D. 0.4 · A. 0.0 Explanation: Note that Math.PI is 180 degrees.
Top answer
1 of 2
1

Sorry, but this is not a good idea. The formula that you saw essentially expresses that $$\sin x\approx x$$ when $x$ is small, and the smaller $x$ the more exact the approximation. It is valid for angles in radians.

When the angles are in degrees, this relation becomes

$$\sin°x\approx \frac{\pi x}{180}$$ where $\sin°$ denotes the sine of an angle in radians. So you hope to evaluate

$$\pi\approx180\frac{\sin°x}x.$$

If the function $\sin°$ is not available, you will have to emulate it with an explicit conversion, using

$$\sin°x=\sin\frac{\pi x}{180},$$ so that

$$\pi\approx180\frac{\sin\dfrac{\pi x}{180}}x.$$

So, not only this does not allow you to compute $\pi$ as it requires preliminary knowlegde of $\pi$, but it will do that in a very inefficient and inaccurate way, actually replacing $cx/x$ by $\sin cx/x$. You will spend much energy to go round in circles.

Even when a $\sin°$ function is available, this approach is wrong because the $\sin°$ will do the conversion from degrees to radians anyway (using a hard-coded value of $\pi$), and you will have to use an angle so small that $\sin x=x$ numerically, and there is no more point computing the sine.


A less "schizophrenic" approach is using

$$\pi=4\arctan1$$ (in radians).

2 of 2
0

I am assuming your sin(x) function takes radians, as stated in the OP. Start by assigning x = 3 and then iterate the statement x = x + sin(x) a few times (three iterations should work well). When you are done, x will contain a good approximation to $\pi$.

How does it work? We are using "fixed point iteration" to approximate a root of $x = x + \sin(x)$ near $x = 3$. Reference: Wikipedia, "Fixed-point iteration"

🌐
TutorialKart
tutorialkart.com › java › java-math › java-math-sin
Java Math.sin() - Examples
November 23, 2020 - Java Program · </> Copy · public ... System.out.println(result); } } Output · 0.479425538604203 · 0.5 radians is approximately equal to 28.6 degrees....
🌐
Programiz
programiz.com › java-programming › library › math › sin
Java Math sin()
Note: The value of the angle is in radians. returns the trigonometric sine of the specified angle · returns NaN if the specified angle is NaN or infinity · Note: If the argument is zero, then the result of the sin() method is also zero with the same sign as the argument. import java.lang.Math; ...
🌐
Scribd
scribd.com › doc › 316116459 › ja2
Java Math Functions Explained | PDF | Trigonometric Functions | Sine
Example: public class Test{ public ... value of e is 2.7183 sqrt(11.635) is 3.411 · sin() Description: The method returns the sine of the specified double value....
🌐
Jenkov
jenkov.com › tutorials › java › math-operators-and-math-class.html
Java Math Operators and Math Class
The Java Math class provides more advanced mathematical calculations than what the basic Java math operators provide. The Math class contains methods for finding the maximum or minimum of two values, rounding values, logarithmic functions, square root, and trigonometric functions (sin, cos, tan etc.).
🌐
Scaler
scaler.com › home › topics › java math sin()
Java Math sin() | Scaler Topics
April 14, 2024 - The built-in java.lang.Math.sin() function returns the sine value of the argument supplied. The argument is expected to be in radians. If the argument is NaN (Not-a-Number) or infinity, the function will return NaN as the outcome.
🌐
Quora
quora.com › How-do-you-calculate-the-sin-value-in-Java
How to calculate the sin value in Java - Quora
Answer (1 of 2): First off, if you’re not referring to the function sin() then you should spell it correctly as sine to avoid unnecessary religious jokes. That aside, I alread see an answer referring you to the default Math package thats included with Java, so I’m going to take a different ...
🌐
LinuxQuestions.org
linuxquestions.org › questions › programming-9 › [java]-sines-cosines-and-tangents-one-is-wrong-447408
[Java] Sines, cosines and tangents. One is wrong...
May 22, 2006 - Friends, I am trying to put some lines of codes to learn java and following is what I've ran into today... I was trying to get the basics of
🌐
Mathbits
mathbits.com › JavaBitsNotebook › LibraryMethods › MathClassMethods.html
Java Math Class and Methods - JavaBitsNotebook.com
We have seen that Java contains a set of built-in math operators that perform simple mathematical operations such as addition, subtraction, multiplication, division and modulus. Java also contains the Java Math class which contains "methods" for dealing with more advanced mathematical computations ...