Skip to content

Instantly share code, notes, and snippets.

@matiasvillaverde
Created October 26, 2016 12:03
Show Gist options
  • Save matiasvillaverde/468340a03616ca916c926cafb092b982 to your computer and use it in GitHub Desktop.
Save matiasvillaverde/468340a03616ca916c926cafb092b982 to your computer and use it in GitHub Desktop.
/******************************************************************************
* 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