fork download
  1. import java.util.ArrayList;
  2.  
  3. public class Main {
  4. public static void main(final String[] args) {
  5. for (int n = 1; n <= 100; n++) {
  6. System.out.println(new M(n).fizz().buzz().seven().eleven().weakString());
  7. }
  8. }
  9. }
  10.  
  11. class M {
  12. final int n;
  13. final ArrayList<String> ms;
  14.  
  15. M(final int n) {
  16. this.n = n;
  17. this.ms = new ArrayList<>();
  18. }
  19.  
  20. M fizz() {
  21. return h(3, "Fizz");
  22. }
  23.  
  24. M buzz() {
  25. return h(5, "Buzz");
  26. }
  27.  
  28. M seven() {
  29. return h(7, "Seven");
  30. }
  31.  
  32. M eleven() {
  33. return h(11, "Eleven");
  34. }
  35.  
  36. M h(final int i, final String m) {
  37. if ((n % i) == 0) {
  38. ms.add(m);
  39. }
  40. return this;
  41. }
  42.  
  43. String strongString() {
  44. if (ms.size() == 1) {
  45. return ms.get(0);
  46. } else {
  47. return String.valueOf(n);
  48. }
  49. }
  50.  
  51. String weakString() {
  52. if (ms.size() > 0) {
  53. final StringBuilder b = new StringBuilder();
  54. for (final String m : ms) {
  55. b.append(m);
  56. }
  57. return b.toString();
  58. } else {
  59. return String.valueOf(n);
  60. }
  61. }
  62.  
  63. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
1
2
Fizz
4
Buzz
Fizz
Seven
8
Fizz
Buzz
Eleven
Fizz
13
Seven
FizzBuzz
16
17
Fizz
19
Buzz
FizzSeven
Eleven
23
Fizz
Buzz
26
Fizz
Seven
29
FizzBuzz
31
32
FizzEleven
34
BuzzSeven
Fizz
37
38
Fizz
Buzz
41
FizzSeven
43
Eleven
FizzBuzz
46
47
Fizz
Seven
Buzz
Fizz
52
53
Fizz
BuzzEleven
Seven
Fizz
58
59
FizzBuzz
61
62
FizzSeven
64
Buzz
FizzEleven
67
68
Fizz
BuzzSeven
71
Fizz
73
74
FizzBuzz
76
SevenEleven
Fizz
79
Buzz
Fizz
82
83
FizzSeven
Buzz
86
Fizz
Eleven
89
FizzBuzz
Seven
92
Fizz
94
Buzz
Fizz
97
Seven
FizzEleven
Buzz