Tuesday, August 21, 2007

FizzBuzz Assignment

The following codes is my FizzBuzz implementation.

public class FizzBuzz {
public static void main(String[] args) {
int x = 1;
while(x<=100){ if(x%3 == 0){ System.out.print("Fizz\n"); } else if(x%5 == 0){ System.out.print("Buzz\n"); } else if((x%3 == 0) && (x%5 == 0)){ System.out.print("FizzBuzz\n"); } else{ System.out.print(x + "\n"); } x++; } } }

I took one and half hours to finish to implement.
First, I make sure that I can print out numbers from 1 to 100 by using while loop and then debug and run.
Second, I test run IF statment and bound to print multiple of 3 and 5 and then debug and run.
Third, since I implemented the multiple of 3 and 5, then I print the rest of slot as numbers and then debug and run.
I think the most important things is make sure debug and run when did any on each step of implementation, it's help to decrease error appear on large program.

No comments: