Skip to content

Instantly share code, notes, and snippets.

@Ptolemy2002
Created December 18, 2020 20:36
Show Gist options
  • Save Ptolemy2002/962ba3f54cecaff212c5368ee789567c to your computer and use it in GitHub Desktop.
Save Ptolemy2002/962ba3f54cecaff212c5368ee789567c to your computer and use it in GitHub Desktop.
class Main {
public static void test(int roadRunner, int coyote, int edge) {
System.out.println("Roadrunner Position: " + roadRunner + "; Coyote Position: " + coyote + "; edge: " + edge + ";");
System.out.println();
if (!(roadRunner < edge)) {
System.out.println("Roadrunner did not run.");
}
//while (!edge)
while (roadRunner < edge) {
//run();
roadRunner++;
System.out.println("Roadrunner ran. Position: " + roadRunner);
if (roadRunner > edge) {
System.out.println("Off the edge!");
} else {
System.out.println("Not off the edge.");
}
}
System.out.println();
//do while (!edge)
do {
//run();
coyote++;
System.out.println("Coyote ran. Position: " + coyote);
if (coyote > edge) {
System.out.println("Off the edge!");
} else {
System.out.println("Not off the edge.");
}
} while (coyote < edge);
}
public static void main(String[] args) {
System.out.println("Neither Coyote nor roadrunner are on the edge:");
test(0, 0, 1);
System.out.println("---------------------------");
System.out.println("Coyote and roadrunner are both on the edge:");
test(1, 1, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment