fork download
  1. class myInteger {
  2. private int n;
  3. private StringBuffer buff;
  4. private myInteger fizzbuzzgizz(int m, String mes) {
  5. if (this.n % m == 0) { buff.append(mes); }
  6. return this;
  7. }
  8. public myInteger(int n) { this.n = n; buff = new StringBuffer(); }
  9. public String toString() {
  10. if (this.buff.length() == 0)
  11. return new Integer(n).toString();
  12. else
  13. return buff.toString();
  14. }
  15.  
  16. public myInteger fizz() { return this.fizzbuzzgizz(3, "Fizz"); }
  17. public myInteger buzz() { return this.fizzbuzzgizz(5, "Buzz"); }
  18. public myInteger gizz() { return this.fizzbuzzgizz(7, "Gizz"); }
  19. }
  20.  
  21. class Main {
  22. public static void main(String[] args) {
  23. System.out.println(new myInteger(1).fizz().buzz().gizz());
  24. System.out.println(new myInteger(3).fizz().buzz().gizz());
  25. System.out.println(new myInteger(5).fizz().buzz().gizz());
  26. System.out.println(new myInteger(7).fizz().buzz().gizz());
  27. System.out.println(new myInteger(15).fizz().buzz().gizz());
  28. System.out.println(new myInteger(21).fizz().buzz().gizz());
  29. System.out.println(new myInteger(35).fizz().buzz().gizz());
  30. System.out.println(new myInteger(105).fizz().buzz().gizz());
  31. System.out.println(new myInteger(997).fizz().buzz().gizz());
  32. }
  33. }
  34. /* end */
  35.  
Success #stdin #stdout 0.02s 246656KB
stdin
Standard input is empty
stdout
1
Fizz
Buzz
Gizz
FizzBuzz
FizzGizz
BuzzGizz
FizzBuzzGizz
997