go to previous page   go to home page   go to next page hear noise highlighting

Answer:

radians


Radians

As is normal for most calculators (and most programming languages), the arguments for Java's trigonometric functions are in radians. Unlike most calculators, you can't push a button and switch to degrees. Here is an example program:

import java.util.*;

public class CosineCalc
{
  public static void main (String[] args)  
  {
    double value;
    Scanner scan = new Scanner( System.in );
 
    System.out.print("Enter radians:");
    value = scan.nextDouble();
    
    // calculate its cosine
    double result = Math.cos( value );
    
    // write out the result
    System.out.println("cosine: " + result );
  }
}

Here is an example run:

C:\chap13>java CosineCalc
Enter radians:1.5
cosine: 0.0707372016677029

QUESTION 19:

What do you suspect is the data type of the argument and return value for Math.cos()?


go to previous page   go to home page   go to next page