This is the syntax highlighted version of Polar.java.
/*************************************************************************
* Compilation: javac Polar.java
* Execution: java Polar x y
*
* Read in Cartesian coordinates (x, y) and print out polar coordinates
* (r, theta).
*
*************************************************************************/
public class Polar {
public static void main(String[] args) {
double x = Double.parseDouble(args[0]);
double y = Double.parseDouble(args[1]);
double r = Math.sqrt(x*x + y*y);
double theta = Math.atan2(x, y);
System.out.println("r = " + r);
System.out.println("theta = " + theta);
}
}
Last updated: Wed Feb 11 18:07:23 EST 2004
.
Copyright © 2004, Robert Sedgewick and Kevin Wayne.