Monday, August 31, 2009

My FizzBuzz Program

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 % 5 == 0) {
System.out.println("Buzz");
}
else if (i % 3 == 0) {
System.out.println("Fizz");
}
else System.out.println(i);
}
}
}

It took me about 10 - 15 minutes to write this program on eclipse. When I originally solved this problem on a sheet of paper, I wrote the first if statement as if((i%5==0)&&(i%3==0)), however I realized later that writing it as above is much clearer.

I would have to say that since I am not used to programming on eclipse, it took me much longer to program this FizzBuzz program than usual. But I feel that once I get the hang of all the GUI functionality and additional features that eclipse provides, I will then be able to code much faster.

No comments:

Post a Comment