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
🌐
W3Schools
w3schools.com › java › ref_math_cos.asp
Java Math cos() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate · ❮ Math Methods · Return the cosine of different angles: System.out.println(Math.cos(3)); System.out.println(Math.cos(-3)); System.out.println(Math.cos(0)); System.out.println(Math.cos(Math.PI)); System.out.println(Math.cos(Math.PI/2)); Try it Yourself » ·
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_cos.htm
Java - Math cos(double) Method
The Java Math cos(double a) returns the trigonometric cosine of an angle.If the argument is NaN or an infinity, then the result is NaN. The computed result must be within 1 ulp of the exact result.
🌐
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); ...
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › cos
Java Math cos() - Calculate Cosine | Vultr Docs
September 27, 2024 - The Math.cos() function in Java calculates the cosine of a specified angle given in radians.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-cos-method
Java Math cos() Method - GeeksforGeeks
May 12, 2025 - In Java, the Math.cos() method returns the trigonometric cosine of an angle. This method calculates the cosine of the angle, which must be provided in radians. If the argument is NaN or an infinity, then the result returned is NaN.
🌐
Codecademy
codecademy.com › docs › java › math methods › .cos()
Java | Math Methods | .cos() | Codecademy
May 15, 2024 - The .cos() method returns the trigonometric cosine of the given angle. The result is in the range [-1, 1]. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
🌐
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:
🌐
Tutorialspoint
tutorialspoint.com › java › number_cos.htm
Java - cos() Method
Java Vs. C++ ... The method returns the cosine of the specified double value.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › java math cos()
Java Math cos() | Scaler Topics
April 14, 2024 - Math cos() method returns the trigonometric cosine of the specified angle It also returns NaN if the specified angle is NaN or infinity. The Math.cos() method in Java does not throw any exceptions.
🌐
Tutorial Gateway
tutorialgateway.org › home › java › java cos function
Java cos Function
March 26, 2025 - The Java cos Function is a Math Library function used to calculate the Trigonometry Cosine for a given expression Syntax Math.cos (double x)
🌐
GeeksforGeeks
geeksforgeeks.org › java › trigonometric-functions-in-java-with-examples
Trigonometric Functions in Java with Examples - GeeksforGeeks
May 27, 2019 - // Java program for cos() method ... to radians double radians = Math.toRadians(degrees); // cos() method to get the cosine value double cosValue = Math.cos(radians); // prints the cosine value System.out.println("cos(" + degrees ...
🌐
AlphaCodingSkills
alphacodingskills.com › java › note › java-math-cos.php
Java Math cos() Method - AlphaCodingSkills
In the example below, cos() method is used to find out the trigonometric cosine of an angle. public class MyClass { public static void main(String[] args) { System.out.println(Math.cos(Math.PI/6)); System.out.println(Math.cos(Math.PI/4)); System.out.println(Math.cos(Math.PI/3)); } } ... ...
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › acos
Java Math acos() - Compute Arc Cosine | Vultr Docs
December 3, 2024 - The Math.acos() method in Java is used to compute the arc cosine of a given angle, returned in radians.
🌐
BeginnersBook -
beginnersbook.com › home › java › java math.cos() method
Java Math.cos() Method
October 17, 2022 - Java Math.cos() method returns the trigonometric cosine of the given angle in radians. This angle value is passed as an argument to this method and it returns the cosine value ranging from -1 to 1.
🌐
Java Guides
javaguides.net › 2024 › 06 › java-math-cos-method.html
Java Math cos() Method
June 24, 2024 - The Math.cos() method in Java provides a way to calculate the cosine of a given angle in radians.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › number_cos.htm
Java - Math.cos() Method
The java.lang.Math.cos(double a) returns the trigonometric cosine of an angle. Special Cases: If the argument is NaN or an infinity, then the result is NaN.
🌐
Javatpoint
javatpoint.com › java-math-cos-method
Java Math.cos() Method with Examples - Javatpoint
August 9, 2023 - Java Program to divide a string in 'N' equal parts.
🌐
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 - @dandan is spot on: Java’s Math.cos expects radians. 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. Also, avoid overwriting your input angle like in your snippet; keep the degrees and the cosine in separate variables.