Monday, August 31, 2009

FizzBuzz

Writing a program for FizzBuzz is a quite relaxing program practice. It takes me about 1o minutes to finish this task. Out of this 10 minutes, I spent at least 6 minutes in creating a new project in Eclipse:(

When I first time started Eclipse, I was shocked by the "user-friendly" interface of the Eclipse welcome page. It has some icons, but I cannot find any icon for creating a new project. Therefore, I had to look carefully so that I can successfully click on the "file" button on the small menu bar to start a new Java project. Maybe the next version for Eclipse IDE will have a simple start page instead of an abstract welcome page.

The start up for me is not very smooth, but the environment is very friendly. It provides helpful hints if there is something unusual in the code. With such facility, I can write my code more efficiently.

Basically, this is my experience about writing a FizzBuzz program in Eclipse.

Here is my code:


public class FizzBuzzClass {

public static void main(String[] args){

for(int i = 1; i <= 100; i++)

{System.out.println(GetFizzBuzz(i)); }

}
static String GetFizzBuzz(int n)

{

if(n%3==0&&n%5==0)

{ return "FizzBuzz"; }

else if(n%3==0)

{ return "Fizz"; }

else if(n%5==0)

{ return "Buzz"; }

else { return Integer.toString(n);

}

}

}

No comments:

Post a Comment