Skip to content

Instantly share code, notes, and snippets.

@steventhanna
Created February 22, 2015 17:42
Show Gist options
  • Select an option

  • Save steventhanna/8d71e21da7d5f70fe9d4 to your computer and use it in GitHub Desktop.

Select an option

Save steventhanna/8d71e21da7d5f70fe9d4 to your computer and use it in GitHub Desktop.
The FizzBuzz Test in java
/**
* @author Steven T Hanna
* @class FizzBuzz
* @date 2/22/15
* @description Complete the FizzBuzz test in Java
*/
public class FizzBuzz {
public static void main(String[] args) {
// Write a program that prints the numbers from 1 - 100.
// But for multiples of 3 print "Fizz" instead of the number
// For multiples of five print "Buzz". For numbers which are
// multiples of both three and five print "FizzBuzz"
for(int i = 0; i <= 100; i++) {
if((i % 3 == 0) || (i % 5 == 0)) {
if(i % 3 == 0) {
System.out.print("Fizz");
}
if(i % 5 == 0) {
System.out.print("Buzz");
}
} else {
System.out.print(i);
}
System.out.println("");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment