# 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 Arc Sine value.

• If the number argument is positive or negative double value, the Math.asin 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, the Math.asin function will return NaN.

Return Type: Java Math.asin Function will return the values between -Π / 2 and Π /2

## Java asin Function Example

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

```// Java Math.asin Function

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));

System.out.println("\nArc Sine value of Radiant = " + Math.asin(m));
}
}```

First, we declared variable x of type Double and used the Java 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);```

Math.asin(1.96 – 4.65 + 2.98)

==> Math.asin (0.29) ==> 0.294

Next, we used the Math.asin 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

```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));```

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

```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));```

Next, 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 to print the result as output.

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

## Java asin on Array example

In this Java program, we find the Arcsine values of bulk data. Here, we are going to declare an array of double type and find the arcsine values of array elements using Java 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 the Java For Loop to iterate the Array. Within the asin 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 Java asin Function directly inside the System.out.format statement. Here, it will call the Math.asin 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);

for (double x : myList) {
System.out.format("Arc Sine value of ArrayList Item %.2f =  %.4f \n", x, Math.asin(x));
}
}
}```
``````Arc Sine value of ArrayList Item 0.79 =  0.9033
Arc Sine value of ArrayList Item 0.52 =  0.5511
Arc Sine value of ArrayList Item 0.39 =  0.4036
Arc Sine value of ArrayList Item 0.35 =  0.3566
Arc Sine value of ArrayList Item 0.08 =  0.0786
Arc Sine value of ArrayList Item 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)

```ArrayList<Double> myList = new ArrayList<Double>(5);
`for (double x : myList) {`
`System.out.format("Arc Sine value of ArrayList Item %.2f =  %.4f \n", x, Math.asin(x));`