use Math.toRadians to convert your degrees to radians to pass to Math.cos for example

double blah = Math.cos(Math.toRadians(50));

I think that is what you are asking. There are quite a lot of similar questions here.

Answer from azp74 on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-cos-method
Java Math cos() Method - GeeksforGeeks
May 12, 2025 - First, we are converting the degrees into radians using Math.toRadian(a) method and then we are using Math.cos(b) for calculating the cosine of the angle and then printing the result.
🌐
Tutorialspoint
tutorialspoint.com › java › number_cos.htm
Java - cos() Method
public class Test { 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 cosine of %.1f degrees is %.4f%n", degrees, Math.cos(radians)); } } This will produce the following result − · The value of pi is 3.1416 The cosine of 45.0 degrees is 0.7071 · java_numbers.htm ·
🌐
CodeGym
codegym.cc › java blog › java math › math.cos() method in java
Math.cos() method in Java
October 11, 2023 - The double cos (double x) method of the Math class returns the cosine value of the x, where x is an argument, an angle in radians. Here is a declaration of the Java.lang.Math.cos() Method: double cos(double x) If you are uncomfortable with ...
🌐
Programiz
programiz.com › java-programming › library › math › cos
Java Math cos()
returns the trigonometric cosine of the specified angle · returns NaN if the specified angle is NaN or infinity · import java.lang.Math; class Main { public static void main(String[] args) { // create variable in Degree double a = 30; double b = 45; // convert to radians a = Math.toRadians(a); ...
🌐
Codecademy
codecademy.com › docs › java › math methods › .cos()
Java | Math Methods | .cos() | Codecademy
May 15, 2024 - double radian = degree * pi/180; //to get output up to the first decimal place · double roundedResult = Math.round(Math.cos(radian) * 10.0) / 10.0; System.out.println("Cosine of 60 degrees is " + roundedResult); } } Copy to clipboard · Copy ...
🌐
TutorialKart
tutorialkart.com › java › java-math › java-math-cos
Java Math.cos() - Examples
November 23, 2020 - Java Program · </> Copy · public ...intln(result); } } Output · 0.8775825618903728 · 0.5 radians is approximately equal to 28.6 degrees....
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_cos.htm
Java - Math cos(double) Method
package com.tutorialspoint; public class MathDemo { public static void main(String[] args) { // get a variable x which is equal to PI/2 double x = Math.PI / 2; // convert x to radians x = Math.toRadians(x); // get the arc sine of x System.out.println("Math.cos(" + x + ")=" + Math.cos(x)); } } Let us compile and run the above program, this will produce the following result − ... The following example shows the usage of Math cos() method of 0° angle.
Find elsewhere
🌐
Java Tutorial HQ
javatutorialhq.com › java tutorial › java.lang › math › cos() method example
Java Math cos() method example
September 30, 2019 - package com.javatutorialhq.java.examples; import java.util.Scanner; /* * This example source code demonstrates the use of * cos() method of Math class */ public class MathCosineExample { public static void main(String[] args) { // Ask for user input System.out.print("Enter an angle in degrees:"); // use scanner to read the console input Scanner scan = new Scanner(System.in); // Assign the user to String variable String s = scan.nextLine(); // close the scanner object scan.close(); // convert the string input to double double value = Double.parseDouble(s); // convert the value to radians double valueRadians = Math.toRadians(value); // get the cosine of the angle double cosValue = Math.cos(valueRadians); System.out.println("cosine of " + s + " is " + cosValue); } }
🌐
Tutorialspoint
tutorialspoint.com › java › lang › number_cos.htm
Java - Math.cos() 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 cos of %.1f degrees is %.4f%n", degrees, Math.cos(radians)); } } This will produce the following result − · The value of pi is 3.1416 The cos of 0.0 degrees is 1.0000 · java_numbers.htm ·
🌐
BeginnersBook -
beginnersbook.com › home › java › java math.cos() method
Java Math.cos() Method
October 17, 2022 - This angle value is passed as an argument to this method and it returns the cosine value ranging from -1 to 1. For example, Math.cos(Math.toRadians(0)) returns 1.0. public class JavaExample { public static void main(String[] args) { double degrees = 0; //conversion degree to radians double ...
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 38605 › the-problem-with-using-java-s-maths-cos
user interface - The problem with using Java's maths.cos() | DaniWeb
January 25, 2006 - The tiny nonzero results you saw at 90 and 270 degrees are just floating-point rounding. pi is not exactly representable, so cos(pi/2) comes out around 6e-17 instead of 0. Treat very small magnitudes as zero when displaying.
🌐
Scaler
scaler.com › home › topics › java math cos()
Java Math cos() | Scaler Topics
April 14, 2024 - The value is stored in a'; it is then converted to radians using the Math. radians ()function and stored inb; we then use the cos()method onb` to obtain its cosine value. Let’s see the implemenation of cos() with Double.POSITIVE_INFINITY in Java
🌐
Baeldung
baeldung.com › home › algorithms › using math.sin with degrees
Using Math.sin with Degrees | Baeldung
January 25, 2024 - In this short tutorial, we’ll look at how to calculate sine values using Java’s Math.sin() function and how to convert angle values between degrees and radians.
🌐
GeeksforGeeks
geeksforgeeks.org › java › trigonometric-functions-in-java-with-examples
Trigonometric Functions in Java with Examples - GeeksforGeeks
May 27, 2019 - // Java program for sin() method ... } } Output: ... Java.lang.Math.cos() : is an inbuilt method which returns the cosine of the value passed as an argument....
🌐
Dirask
dirask.com › posts › Java-Math-cos-method-example-p5GZ41
Java - Math.cos() method example
public class MathExample { static double calculateCos(double deg) { double rad = (Math.PI / 180) * deg; return Math.cos(rad); } public static void main(String[] args) { double x1 = 0.0; // beginning of calculation in degrees double x2 = 90.0; // ending of calculation degrees double dx = 15.0; // calculation step in degrees for (double deg = x1; deg <= x2; deg += dx) { double y = calculateCos(deg ); System.out.println("cos(" + deg + " deg) = " + y); } } }
🌐
W3Schools
w3schools.com › java › ref_math_cos.asp
Java Math cos() Method
The cos() method returns the cosine of an angle. Note: Angles are measured in radians. Tip: You can use the constant Math.PI to make fractions of PI for angles. ... If you want to use W3Schools services as an educational institution, team or ...