8/27/2008

Implementation of FizzBuzz

Tasks:
To implement a program which prints number from 1 to 100, one per line. Exception is, for mutiple of 3 it should print "Fizz", for mutiple of 5 it should print "Buzz", for mutiple of 3 and 5 it should print "FizzBuzz".

Observation:
I didn't have any problem writing this program since it was covered in class. It took less than 5 minutes to make it. However, the more important thing I learned is how to write a test case. With that we are able to know how the value is going to be.

I knew Eclipse has thousands of features for software development, but I didn't know how to use it so I was using Notepad. This semester I'm looking forward to learn those and be able to develop software more efficiently.

Code: 

public class FizzBuzz {
public static void main(String[] args) {
for (int i=1; i<=100; i++) {
if ((i%15) == 0)
System.out.println("FizzBuzz");
else if ((i%3) == 0)
System.out.println("Fizz");
else if ((i%5) == 0)
System.out.println("Buzz");
else
System.out.println(i);
}
}
}