I wanted to try FizzBuzz, but to do it in the most efficient way. I think this method employs most of the concepts I learned here. Is there anything unaccounted for? A sprinkle of Swing since that's what I've been focusing on lately.
import javax.swing.JOptionPane;
public class FizzBuzzCounter {
public static void main(String[] args) {
int goalNumber = Integer.parseInt(JOptionPane.showInputDialog("FizzBuzz goal number?"));
fizzBuzzify(goalNumber);
}
public static void fizzBuzzify(int n) {
for (int i = 1; i <= n; i++) {
StringBuilder sb = new StringBuilder();
if (i % 3 == 0) sb.append("Fizz");
if (i % 5 == 0) sb.append("Buzz");
if (sb.toString().isEmpty()) System.out.println(i);
else System.out.println(sb.toString());
}
}
}