Tuesday, August 25, 2009

FizzBuzz Application

During the first day of Software Engineering class, we had to write the FizzBuzz application on paper which was hard since I didn't remember all the java syntax at that moment. One of this week's assignments was to write the appplication in Eclipse. After a 10 minute review of the Java syntax this application took me about five minutes to implement. It was a good way for me to get back into the groove of programming since I haven't been done it for quite some time now. I didn't encounter any problems during the writing of this application.

The code below implements the FizzBuzz application.



public class FizzBuzz {
//FizzBuzz application prints FizzBuzz for numbers that are both multiples of 3 and 5. It prints Buzz for mulitples of 5 and Fizz for multiples of 3.

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);
}
}
}
}

No comments:

Post a Comment

 
/*Java2HTML*/