Skip to content

Instantly share code, notes, and snippets.

@brianmacdonald
Created March 5, 2010 00:07
Show Gist options
  • Save brianmacdonald/322291 to your computer and use it in GitHub Desktop.
Save brianmacdonald/322291 to your computer and use it in GitHub Desktop.
/*
* Title: Fizzbuzz (Java Coding Sample)
* Author: Brian Macdonald
* Description:
* Program that prints the numbers from 1 to 100. But for multiples of
* three print "Fizz" instead of the number and for the multiples of five
* print "Buzz". For numbers which are multiples of both three and five
* print "FizzBuzz".
*/
class FizzBuzz{
public static void main(String args[]){
for (int x = 1; x <= 100; x++){
if ((x % 3 == 0) && (x % 5 == 0)){
System.out.println("FizzBuzz");
} else if(x % 3 == 0){
System.out.println("Fizz");
} else if(x % 5 == 0){
System.out.println("Buzz");
} else {
System.out.println(x);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment