Skip to content

Instantly share code, notes, and snippets.

@adrienbrault
Created May 5, 2011 12:59
Show Gist options
  • Save adrienbrault/956984 to your computer and use it in GitHub Desktop.
Save adrienbrault/956984 to your computer and use it in GitHub Desktop.
Java fizzbuzz
public class MyFirstProgram {
public static void main(String args[]) {
for(int i = 1; i <= 100; i++) {
boolean mod3 = i % 3 == 0;
boolean mod5 = i % 5 == 0;
boolean lineBreak = (i - 9) % 10 == 0;
if (mod3) {
System.out.print("fizz");
}
if (mod5) {
System.out.print("buzz");
}
if (!mod3 && !mod5) {
System.out.print(i);
}
System.out.print(" ");
if (lineBreak) {
System.out.println("");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment