TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Java Tutorials

    Java Trigonometric Functions with Examples

    Overview

    This tutorial will teach you different Java trigonometric functions with some code examples. These functions are defined in the java.lang.Math class.

    Java Trigonometric Functions

    The following table lists the different Trigonometric functions in the Java Math class. Math is a final class. We cannot instantiate an object for this class and there is no need to create an object for this class. These functions are static and can be accessed with the class name.

     

    Function Description
    sin(x) This function returns the sine of the angle x. The argument x should be in radians.
    cos(x) This function returns the cosine of the angle x. The argument x should be in radians.
    tan(x) This function returns the tangent of the angle x. The argument x should be in radians.
    asin(y) This function returns the angle in radians whose sine is y.
    acos(y) This function returns the angle in radians whose cosine is y.
    atan(y) This function returns the angle in radians whose tangent is y.
    atan2(x,y) This function takes two arguments. It returns the angle in radians whose tangent is x/y.

    Example

    Let’s write a simple Java program to calculate and print the sin, cosine, and tangent of 60 degrees.

    /*
     * Java Trigonometric Functions Examples
     * Java Tutorials - www.TestingDocs.com
     */
    
    public class Trigonometric {
    
     public static void main(String[] args) {
     // π radians = 180 degrees
     System.out.println("Sin(60) degrees =" +
     Math.sin(Math.PI/3));
     System.out.println("Cos(60) degrees =" + 
     Math.cos(Math.PI/3));
     System.out.println("Tan(60) degrees =" + 
     Math.tan(Math.PI/3));
     }
    
    }

     

    Java Trigonometric Functions

    Notice how we have simply invoked the static function with the class name.

    For example, Math.sin(Math.PI/3);

    —

    Java Tutorials

    Java Tutorial on this website:

    https://www.testingdocs.com/java-tutorial/

    For more information on Java, visit the official website :

    https://www.oracle.com/java/

    Related Posts

    Java Performance

    Java Tutorials /

    Improving Java Performance with Multithreading

    Download Greenfoot Windows

    Java Tutorials /

    Download & Install Greenfoot on Windows

    Java Tutorials /

    Java Static Code Analysis

    Java Tutorials /

    Java Testing Tools

    Java Tutorials /

    Handle Multiple Exceptions in Java

    ‹ Java Assignment Statement› Java Arithmetic Expressions

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com