Write a Java program to Find the trigonometric arc cosine of an angle


This Java program demonstrates how to find the arc cosine of a given angle in degrees using the Math.acos() method. Here's how the code works:

  • The java.util.* package is imported to use the Scanner class for user input.
  • The Trigonometric_ArcCosine class is defined with a main() method.
  • Inside the main() method, a new Scanner object called input is created to read user input from the console.
  • A double variable called deg is declared and initialized to 0. This variable will hold the angle in degrees entered by the user.
  • The message "Enter The Degree : " is displayed on the console using the System.out.print() method.
  • The nextDouble() method of the Scanner class is called on the input object to read a double value entered by the user, which is then assigned to the deg variable.
  • The Math.toRadians() method is called to convert the angle in degrees to radians.
  • The Math.acos() method is called on the rad variable to calculate the arc cosine of the angle in radians.
  • The result is displayed on the console using the System.out.print() method with the message "Trigonometric arc Cosine is: " concatenated with the calculated value.

Note that the Math.acos() method returns the arc cosine of an angle in radians. To convert the result back to degrees, you can use the formula degrees = radians * (180 / Math.PI).

Source Code

import java.util.*;
public class Trigonometric_ArcCosine
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		double deg = 0;
 
		System.out.print("Enter The Degree : ");
		deg = input.nextDouble();
 
		double rad = Math.toRadians(deg);
		System.out.print("Trigonometric arc Cosine is: " + Math.acos(rad));
	}
}

Output

Enter The Degree : 23.4
Trigonometric arc Cosine is: 1.150088077902267

Example Programs