Java asin Function

The Java asin Function is one of the Java Math functions, which is to calculate the trigonometric Arc Sine for the specified expression. Arc Sine is also called the inverse of a Sine.

Java asin Function Syntax

The basic syntax of the asin Function in Java Programming language is as shown below.

static double asin(double number); //Return Type is Double

// In order to use in program: 
Math.asin(double number);

Number: It can be a double value or a valid numerical expression for which you want to find the Arc Sine value.

  • If the number argument is a positive or negative double value, the function will return the Arc Sine value.
  • If the number argument is Zero, the Java Math.asin function will return Zero with the same sign.
  • When the number argument is Not a number or outside the range -1 and 1, it will return NaN.

Return Type: This Function will return the values between -π / 2 and π / 2

Java asin Function Example

In this Java program, we use the Math.asin Function to find the trigonometric Arc Sine values of both positive and negative values and display the output.

package TrigonometricFunctions;

public class AsinMethod {
	public static void main(String[] args) {
		double x = Math.asin(1.96 - 4.65 + 2.98);
		System.out.println("Sine value =  " + x);	
		
		System.out.println("\nArc Sine value of Positive Number = " + Math.asin(0.25));
		System.out.println("Arc Sine value of Positive Number=  " + Math.asin(4.28));
		
		System.out.println("\nArc Sine value of Negative Number =  " + Math.asin(-0.85));
		System.out.println("Arc Sine value of Negative Number =  " + Math.asin(-1.95));

		double m = Math.toRadians(30);
		System.out.println("\nArc Sine value of Radiant = " + Math.asin(m));
	}
}
Java asin Function 1

First, we declared variable x of type Double and used the Math.asin function directly on expression. Here, we used Java System.out.println statement to print the Arcsine result as output. Please refer to the Java sin Function article to understand the Sine Function.

double x = Math.asin(1.96 - 4.65 + 2.98);
System.out.println("Sine value =  " + x);

1.96 – 4.65 + 2.98 ==> (0.29) ==> 0.294

Next, we used the Function directly on Positive double values. If you observe the above screenshot, Output of Math.asin (4.28) is giving NaN because the argument value is greater than 1

Next, we used the Java asin Function directly on Negative double values. The Output of Math.asin (-1.95) is giving NaN because the argument value is not in the range -1 and 1

Within the last statements, we declared a variable of type Double and assigned the value. Next, we used the Math.toRadians function to convert 30 into equivalent radiant. Then the Java System.out.println statement prints the result as output.

Java asin on Array example

In this Java program, we find the Arcsine values of bulk data. Here, we will declare an array of double type and find the arcsine values of array elements using the asin function.

package TrigonometricFunctions;

public class AsinMethodOnArrays {
	public static void main(String[] args) {
		
		double [] myArray = {0, 1, -1, 0.30, 0.45, 0.60, 0.75, 0.90};

		for (int i = 0; i < myArray.length; i++) {
			System.out.format("Arc Sine value of Array Element %.2f = %.4f\n", myArray[i], Math.asin(myArray[i]));
		}
	}
}
Arc Sine value of Array Element 0.00 = 0.0000
Arc Sine value of Array Element 1.00 = 1.5708
Arc Sine value of Array Element -1.00 = -1.5708
Arc Sine value of Array Element 0.30 = 0.3047
Arc Sine value of Array Element 0.45 = 0.4668
Arc Sine value of Array Element 0.60 = 0.6435
Arc Sine value of Array Element 0.75 = 0.8481
Arc Sine value of Array Element 0.90 = 1.1198

We used Java For Loop to iterate the Array. Within the For Loop, we initialized the i value as 0. Next, the compiler will check for the condition (i < myArray.length).

TIP: myArray.length finds the length of an array.

for (int i = 0; i < myArray.length; i++) {

Next, we used the Function directly inside the System.out.format statement. Here, it will call the Math method ( static double asin(double number) ) to find the corresponding Arc Sine values and print the output.

System.out.format("Arc Sine value of Array Element %.2f = %.4f\n", myArray[i], Math.asin(myArray[i]));

NOTE: To find the Arc Sine value of a single item, then use: Math.asin(myArray[index_position])

Java asin Function on Arraylist example

In this Java program, we are going to declare an ArrayList of double type and find the Arcsine values of list elements.

package TrigonometricFunctions;

import java.util.ArrayList;

public class AsinMethodOnArraylist {
	public static void main(String[] args) {
		ArrayList<Double> myList = new ArrayList<Double>(5);
		myList.add(Math.PI / 4);
		myList.add(Math.PI / 6);
		myList.add(Math.PI / 8);
		myList.add(Math.PI / 9);
		myList.add(Math.PI / 40);
		myList.add(Math.PI / 2);

		for (double x : myList) {
			System.out.format("Arc Sine of %.2f =  %.4f \n", x, Math.asin(x));
		}
	}
}
Arc Sine of 0.79 =  0.9033 
Arc Sine of 0.52 =  0.5511 
Arc Sine of 0.39 =  0.4036 
Arc Sine of 0.35 =  0.3566 
Arc Sine of 0.08 =  0.0786 
Arc Sine of 1.57 =  NaN 

Within this Java asin function example, we declared an ArrayList of double type using Math.PI constant (its value is approximately 3.14)

Next, we used the For Loop to iterate the double values in ArrayList

for (double x : myList) {

Here, the compiler will call the asin Math function ( static double asin(double x) ) to find the corresponding Arc Sine values and print the output.

System.out.format("Arc Sine value of ArrayList Item %.2f =  %.4f \n", x, Math.asin(x));

NOTE: If you observe the above screenshot, the Output of the Math.asin (Math.PI /2) is giving NaN. This is because 3.14 / 2 = 1.570 (which is greater than 1).