Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs
    • SQL FAQ’s

Java toRadians Function

by suresh

The Java toRadians Function is one of the Java Math Library functions, which is to converts an angle measured in degrees to an approximately equivalent angle measured in radians. In this article, we will show how to use Java Math.toRadians function with example.

The syntax of the Math.toRadians in Java Programming language is

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

// To use in program: 
Math.toRadians(double number);

Number: It can be an angle in degree for which you want to convert as a radian

Java toRadians Function Example

The Math.toRadians Function allows to converts degrees to an approximately equivalent angle measured in radians.

In this toRadians Java program, We are going to find the radians of both positive and negative values and display the output

// Java Math.toRadians Function

package TrigonometricFunctions;

public class ToRadians {
	public static void main(String[] args) {
		double x = Math.toRadians(400.96 + 240.65 - 106.98);
		System.out.println("toRadians Function result =  " + x);	
		
		System.out.println("\nFinding Radians of Zero = " + Math.toRadians(0));
		
		System.out.println("\nFinding Radians of Positive Number = " + Math.toRadians(104.95));
		System.out.println("Finding Radians of Positive Number=  " + Math.toRadians(156.28));
		
		System.out.println("\nFinding Radians of Negative Number =  " + Math.toRadians(-135.85));
		System.out.println("Finding Radians of Negative Number =  " + Math.toRadians(-9.35));
	}
}

OUTPUT

Java toRadians Function 1

ANALYSIS

First, We declared variable x of type Double and used the Java Math.toRadians function directly on expression. Here, we used System.out.println statement to print the radiant result as output.

double x = Math.toRadians(400.96 + 240.65 - 106.98);
System.out.println("toRadians Function result =  " + x);

Next, We used the Math.toRadians Function directly on Positive double values.

System.out.println("\nFinding Radians of Positive Number = " + Math.toRadians(104.95));
System.out.println("Finding Radians of Positive Number=  " + Math.toRadians(156.28));

Next, We used the toRadians Math function directly on Negative double values.

System.out.println("\nFinding Radians of Negative Number =  " + Math.toRadians(-135.85));
System.out.println("Finding Radians of Negative Number =  " + Math.toRadians(-9.35));

Java toRadians on Array example

In this Java program, we convert the bulk data to radians. Here, we are going to declare an Array of double type. Next, we use Java toRadians function to convert the array elements to radians.

package TrigonometricFunctions;

public class ToRadiansOnArrays {
	public static void main(String[] args) {
		
		double [] myArray = {1, 30, 45, 60, 75, 90, 120, 180, 240, 360};

		for (int i = 0; i < myArray.length; i++) {
			System.out.format("Finding Radians of Array Element %.2f is = %.4f\n", myArray[i], Math.toRadians(myArray[i]));
		}
	}
}

OUTPUT

Java toRadians Function 2

ANALYSIS

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

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

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

Here, we used the Math.toRadians Function directly inside the System.out.format statement. It means the compiler will call the Math.toRadians method ( static double toRadians(double number) ) to find the corresponding radiant values.

System.out.format("Finding Radians of Array Element %.2f is = %.4f\n", myArray[i], Math.toRadians(myArray[i]));

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

Java toRadians Function on Arraylist example

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

package TrigonometricFunctions;

import java.util.ArrayList;

public class ToRadiansOnArrayList {
	public static void main(String[] args) {
		ArrayList<Double> myList = new ArrayList<Double>(5);
		myList.add(Math.PI);
		myList.add(Math.PI / 3);
		myList.add(Math.PI / 4);
		myList.add(Math.PI / 6);
		myList.add(Math.PI / 9);
		
		for (double x : myList) {
			System.out.format("Finding Radians of ArrayList Item %.2f =  %.4f \n", x, Math.toRadians(x));
		}
	}
}

OUTPUT

Java toRadians Function 3

ANALYSIS

Within this toRadians function example, We declared an ArrayList of double type and assigned random values using Math.PI constant (its value is approximately 3.14).

ArrayList<Double> myList = new ArrayList<Double>(5);
myList.add(Math.PI);
myList.add(Math.PI / 3);
myList.add(Math.PI / 4);
myList.add(Math.PI / 6);
myList.add(Math.PI / 9);

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

for (double x : myList) {

Here, the compiler will call the math.toRadians method ( static double toRadians(double x) ) to find the corresponding radiant value, and prints the output.

System.out.format("Finding Radians of ArrayList Item %.2f =  %.4f \n", x, Math.toRadians(x));

Placed Under: Java

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy