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 ... System.out.println(Math.cos(Math.PI/2)); Try it Yourself » · The cos() method returns the cosine of an angle....
🌐
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!
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › cos
Java Math cos() - Calculate Cosine | Vultr Docs
September 27, 2024 - Understand that Math.cos() expects the angle in radians, not degrees. To find the cosine of an angle in degrees, first convert the angle to radians and then apply the cos() function.
🌐
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. Results must be semi-monotonic. Following is the declaration for java.lang.Math.cos() method ...
🌐
Tutorialspoint
tutorialspoint.com › java › number_cos.htm
Java - cos() Method
The method returns the cosine of the specified double value. Here is the detail of parameters − This will produce the following result −
🌐
CodeGym
codegym.cc › java blog › java math › math.cos() method in java
Math.cos() method in Java
October 11, 2023 - double toDegrees(double angRad) ... 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)); ...
🌐
Programiz
programiz.com › java-programming › library › math › cos
Java Math cos()
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); b = Math.toRadians(b); // print the cosine value System.out.println(Math.cos(a)); // 0.8660254037844387 System.out.println(Math.cos(b)); // 0.7071067811865476 } } In the above example, we have imported the java.lang.Math package. This is important if we want to use methods of the Math class.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › java math cos()
Java Math cos() | Scaler Topics
April 14, 2024 - The Math.cos() method is then used to calculate the cosine values of the angles, which are subsequently printed to the console as 0.8660254037844387 and 0.7071067811865476, respectively.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-cos-method
Java Math cos() Method - GeeksforGeeks
May 12, 2025 - Return Type: This method returns the trigonometric cosine of the given angle. Now, we are going to discuss some examples for better understanding. Example 1: In this example, we will see the basic usage of Math.cos() method.
🌐
Tutorial Gateway
tutorialgateway.org › home › java › java cos function
Java cos Function
March 26, 2025 - The basic syntax of the Math.cos in Java Programming language is as shown below. static double cos(double number); //Return Type is Double // In order to use in program: Math.cos(double number);
🌐
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); } } The above java example source code demonstrates the use of cos() method of Math class.
🌐
Java Guides
javaguides.net › 2024 › 06 › java-math-cos-method.html
Java Math cos() Method
June 24, 2024 - The Math.cos() method in Java is used to return the trigonometric cosine of a given angle.
🌐
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 ... = " + sinValue); } } Output: ... Java.lang.Math.cos() : is an inbuilt method which returns the cosine of the value passed as an argument....
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › acos
Java Math acos() - Compute Arc Cosine | Vultr Docs
December 3, 2024 - ... double invalidResult = ... unrepresentable result. Define two vectors in the plane. Use the dot product and magnitude of vectors to find the cosine of the angle....
🌐
Tutorialspoint
tutorialspoint.com › java › lang › number_cos.htm
Java - Math.cos() Method
Then using Math.toRadians() method we're retrieving the radian and then using Math.cos() method we've printed the cos value. 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", ...
🌐
Sanfoundry
sanfoundry.com › java-program-implement-cos-function
Java Program to Implement the cos() Function
April 29, 2023 - Problem Description Given an angle say x, in degrees find out the cosine of the angle approximately. Problem Solution The cosine of an angle x can be calculated using the following equation cos x = 1 – (x2)/2! + (x4)/4! ...
🌐
AlphaCodingSkills
alphacodingskills.com › java › notes › java-math-cos.php
Java Math cos() Method - AlphaCodingSkills
The java.lang.Math.cos() method returns trigonometric cosine of an angle (angle should be in radians). In special cases it returns the following: If the argument is NaN or an infinity, then the result is NaN. In the graph below, cos(x) vs x is plotted. public static double cos(double a) Returns ...
🌐
Coderanch
coderanch.com › t › 400057 › java › Math-functions-cosine-problems
Math functions cosine problems (Beginning Java forum at Coderanch)
June 26, 2005 - If you have degrees, it must be coverted prior to calling the cosine method. BTW, I don't think I was implying anything... certainly didn't attempt to sound condesending. Henry [ June 26, 2005: Message edited by: Henry Wong ] Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor) ... found the solution. Dont use degrees.