- customer / employer happy
- developers happy, and
- infrastructure happy
Write a 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".
public class FizzBuzz { public static void main(String[] args) { boolean fizzOrBuzz; for (int i = 1; i <= 100; i++) { fizzOrBuzz = false; if (i % 3 == 0) { fizzOrBuzz = true; System.out.print("Fizz"); } if (i % 5 == 0) { fizzOrBuzz = true; System.out.print("Buzz"); } if (!fizzOrBuzz) { System.out.print(i); } System.out.println(); } } }
Update (06/12/2014): https://github.com/codingsince1985/FizzBuzz
No comments:
Post a Comment