fork download
  1. interface Endl {
  2. abstract void endl(myInteger i);
  3. }
  4.  
  5. class myInteger {
  6. private int n;
  7. private boolean flag;
  8. private myInteger fizzbuzzgizz(int m, String mes, Endl endl) {
  9. if (this.n % m == 0) {
  10. this.flag = false;
  11. System.out.print(mes);
  12. }
  13. if (endl != null) endl.endl(this);
  14. return this;
  15. }
  16. public myInteger(int n) { this.n = n; flag = true; }
  17. public myInteger fizz() { return this.fizzbuzzgizz(3, "Fizz", null); }
  18. public myInteger buzz() { return this.fizzbuzzgizz(5, "Buzz", null); }
  19. public myInteger gizz() { return this.fizzbuzzgizz(7, "Gizz", new Endl() {
  20. public void endl(myInteger i) {
  21. if (i.flag == true)
  22. System.out.println(i.n);
  23. else
  24. System.out.println();
  25. } }); }
  26. }
  27.  
  28. class Main {
  29. public static void main(String[] args) {
  30. new myInteger(1).fizz().buzz().gizz();
  31. new myInteger(3).fizz().buzz().gizz();
  32. new myInteger(5).fizz().buzz().gizz();
  33. new myInteger(7).fizz().buzz().gizz();
  34. new myInteger(15).fizz().buzz().gizz();
  35. new myInteger(21).fizz().buzz().gizz();
  36. new myInteger(35).fizz().buzz().gizz();
  37. new myInteger(105).fizz().buzz().gizz();
  38. new myInteger(997).fizz().buzz().gizz();
  39. }
  40. }
  41. /* end */
  42.  
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
1
Fizz
Buzz
Gizz
FizzBuzz
FizzGizz
BuzzGizz
FizzBuzzGizz
997