News for hackers. Stuff that matters.
Re:FizzBuzz: the test helps filter out the 99.5% of programm... by ivanche on Tuesday December 23, 2014 @05:52AM (#8787635)
I'm a little bit surprised of "if-else if-else if" mindset in c2.com wiki entry for this. I always thought of FizzBuzz solution without a single else, like this:

  for (int i = 1; i <= 100; ++i) {
    boolean pureNumba = true;
    if (i % 3 == 0) {
      System.out.print("Fizz");
      pureNumba = false;
    }
    if (i % 5 == 0) {
      System.out.print("Buzz");
      pureNumba = false;
    }
    if (pureNumba) {
      System.out.print(i);
    }
    System.out.println();
  }
Re:FizzBuzz: the test helps filter out the 99.5% of programm... by thaumaturgy on Tuesday December 23, 2014 @06:40AM (#8787753)
Whether an extra variable is better than an extra conditional is mostly a matter of taste. Yours gets the job done too.
Re:FizzBuzz: the test helps filter out the 99.5% of programm... by mapimopi on Tuesday December 23, 2014 @09:01AM (#8788106)
Why not just

  if (i % 3 != 0 && i % 5 != 0)
this extra boolean variable out?
Re:FizzBuzz: the test helps filter out the 99.5% of programm... by ivanche on Tuesday December 23, 2014 @09:57AM (#8788308)
I like to think it's matter of readability. "if (pureNumber)" vs. "if (i % 3 != 0 && i % 5 != 0)". Also, one extra variable vs. reversal of already mentioned condition. Yes, we're splitting hair here :)
Re:FizzBuzz: the test helps filter out the 99.5% of programm... by harpb on Tuesday December 23, 2014 @02:44PM (#8789815)
The solution doesn't takes into consideration the 'fizzbuzz' output. Your solution would print both fizz and buzz when the int is divisible by both 3 and 5.
Re:FizzBuzz: the test helps filter out the 99.5% of programm... by areyousure on Tuesday December 23, 2014 @06:46PM (#8790848)
"For numbers which are multiples of both three and five print “FizzBuzz”."