Of course! You memorized that formula in high school (and forgot five minutes later).
Actually the formula is not that bad:
radians = (Math.PI/180.0)*degrees;
Since this is so common, the Math class has
convenient methods:
public static double toRadians(double angdeg) Converts an angle measured in degrees to the equivalent in radians public static double toDegrees(double angrad) Converts an angle measured in radians to the equivalent in degrees.
Here is our sample program:
import java.util.* ;
public class CosineCalc
{
public static void main (String[] args)
{
Scanner scan = new Scanner( System.in );
double degrees;
// read in the degrees
System.out.print ("Enter degrees:");
degrees = scan.nextDouble();
// calculate its cosine
double result = Math.cos();
// write out the result
System.out.println("cosine: " + result );
}
}
Fill in the blank so that the program works.