Created
October 26, 2016 12:03
-
-
Save matiasvillaverde/468340a03616ca916c926cafb092b982 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
* Compilation: javac Distance.java | |
* Execution: java Distance x y | |
* | |
* Prints the distance from (x, y) to the origin, where x and y | |
* are integers. | |
* | |
* % java Distance 45 -2 | |
* distance from (3, 4) to (0, 0) = 45.044422518220834 | |
* | |
* % java Distance 5 12 | |
* distance from (5, 12) to (0, 0) = 13.0 | |
* | |
******************************************************************************/ | |
public class Distance { | |
public static void main(String[] args){ | |
int x = Integer.parseInt(args[0]); | |
int y = Integer.parseInt(args[1]); | |
double distance = Math.sqrt(x*x + y*y); | |
System.out.print("Distance from (" + x + " , " + y + ") to (0, 0) = " + distance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment