Skip to content

Instantly share code, notes, and snippets.

@KanzakiRanko1
Last active July 31, 2020 14:04
Show Gist options
  • Select an option

  • Save KanzakiRanko1/b740c86113f9b7c24e162a6d078f7a29 to your computer and use it in GitHub Desktop.

Select an option

Save KanzakiRanko1/b740c86113f9b7c24e162a6d078f7a29 to your computer and use it in GitHub Desktop.
Most obvious way to generate code to check if a number is even, duh.
public class Main {
public static void main(String[] args) {
boolean last;
last = false;
System.out.println("private bool IsEven(int number) {");
for (int i = 1; i <= Integer.MAX_VALUE; i++) {
System.out.println(" %s if (number == %d) return %b;", int==1?"":"else", i, last);
last = !last;
}
System.out.println("}");
}
}
@KanzakiRanko1
Copy link
Author

Run the script, pipe output to a file and you'll have an ideal even check function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment