Created
May 5, 2011 12:59
-
-
Save adrienbrault/956984 to your computer and use it in GitHub Desktop.
Java fizzbuzz
This file contains 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
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