One problem I encountered was syntax errors. I originally wrote this program with a pencil and paper, and thus did not catch some errors. I realized what a difference IDE's such as Eclipse makes.
Even though this seemed like a simple program to write, I learned that software engineering starts at the basics. One must start off knowing the fundamentals and build on that in order to become a better programmer.
/**
* FizzBuzz
* Iterates through numbers 1 to 100
* Prints "FizzBuzz" when number is multiple of 3 and 5.
* Prints "Fizz" when number is multiple of 3.
* Prints "Buzz" when number is multiple of 5.
* Prints the number otherwise.
*/
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);
}
}
}
}
0 comments:
Post a Comment