Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am apetz on github.
  • I am tonypetz (https://keybase.io/tonypetz) on keybase.
  • I have a public key ASAT9HdjmAwXCv0XyafODxSsWpWS-RaN-BkBfa0uweCQ3go

To claim this, I am signing this object:

@apetz
apetz / FizzBuzz.java
Last active June 21, 2017 15:47
Prints numbers from 1 to 100, with a well-known twist.
/**
* Prints numbers from 1 to 100. For multiples of three, it prints "Fizz" instead of the number and for the multiples
* of five it prints "Buzz" and for prime numbers it also adds a "Bang"
*/
public class FizzBuzz {
public static void main(String[] args) {
for (int i=1; i<=100; i++) {
boolean isPrime = isPrime(i);
if (i % 3 == 0) System.out.print("Fizz");
@apetz
apetz / Pyramid.java
Created June 21, 2017 02:17
Prints a pyramid of stars to STDOUT, of the height provided as a command line argument
/**
* Prints a pyramid of stars to STDOUT, of the height provided as a command line argument.
*
* Takes only one command line argument (height, as a positive integer).
*/
public class Pyramid {
public static void main(String[] args) {
if (args.length == 0) {
System.err.println("Must supply the desired height (as positive integer) as the first argument");
@apetz
apetz / ReverseString.java
Last active June 21, 2017 15:54
Reverses the string provided as the first command line argument
import java.util.UUID;
/**
* Reverses the string provided as the first command line argument using recursion
*
* Optional 2nd command line argument of '-p' or '--performanceTest' will run a quick and dirty performance test
* of the iterative versus the recursive solution
*
*/
public class ReverseString {
@apetz
apetz / Names.java
Last active June 21, 2017 16:13
Sorts a collection of names (provided as a static final class variable)
import java.util.Comparator;
import java.util.stream.Stream;
/**
* Program that sorts a given (as a static final class variable) list of names
*
* Takes one (optional) argument that controls whether to sort by first name or last name
*
* usage:
* java Names {-s --surname}
@apetz
apetz / HelloWorld.java
Last active June 21, 2017 16:22
Tony's answer to the SF Offline Programming Challenge "Hello World" problem
import java.util.regex.Pattern;
/**
* A (very) simple program that takes one optional command-line argument <name>
* and prints "Hello, <name>!" to STDOUT
*
* If no command line argument is provided, the program prints "Hello, world!" instead
*
* Can be compiled run using the following:
* $ javac HelloWorld.java