Created
April 3, 2018 20:48
-
-
Save vingkan/2abfa7200b16a4c00b8abfbf6ba59e0a to your computer and use it in GitHub Desktop.
Interview Activity: Help this intro Java student debug their code.
This file contains hidden or 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
class SampleMain { | |
/* | |
* INSTRUCTIONS | |
* Compile: javac SampleMain.java | |
* Run: java SampleMain x1 y1 x2 y2 | |
* Output: Coordinates of the midpoint like so: | |
* >> x: 3, y: 4 | |
*/ | |
public static void main(String[] args){ | |
int[] p1 = {0, 0}; | |
int[] p2 = {3, 0}; | |
int[] midPoint = getMidPoint(p1, p2); | |
System.out.println("x: " + midPoint[0] + ", y: " + midPoint[1]); | |
} | |
public static int[] getMidPoint(int[] p1, int[] p2){ | |
int[] mp = {0, 0}; | |
int x = (p2[0] - p1[0]) / 2; | |
int y = (p2[1] - p1[1]) / 2; | |
return mp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment