/home/wpollock1/public_html/Java/Rad2Deg.java
// Demo of defining a Java 8 Function, and applying it.
// Here we simply convert Radians to the equivalent value in Degrees.
//
// Written 7/2016 by Wayne Pollock, Tampa Florida USA.
import java.util.function.*;
public class Rad2Deg {
public static void main ( String [] args ) {
double radian = 0.0;
// Convert command line argument to a double (Radians):
try {
radian = Double.parseDouble( args[0] );
} catch ( Exception e ) {
System.err.println( "Usage: java Rad2Deg <radians>,\n"
+ "where <radians> is a double value to convert to degrees." );
System.exit( 1 );
}
// Define a function (using lambda notation):
Function<Double,Double> toDegrees = radians -> (180 * radians)/Math.PI;
// Use function:
System.out.printf( "%s Radians = %4.2f Degrees.%n", args[0],
toDegrees.apply(radian) );
}
}