Guest User

Untitled

a guest
Jan 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. //Author: Yong Hong Hsu
  2. //The FizzBuzz program try to pirnt out number from 1 to 100, except when the number
  3. //is multiple of 3, 5 and both 3 and 5
  4. //Date: 8/29/11
  5. //Time of finishedd: 10 mins
  6.  
  7. public class FizzBuzz {
  8. /**
  9. * @param args
  10. */
  11. public static void main(String[] args) {
  12. // TODO Auto-generated method stub
  13. FizzBuzz fiz = new FizzBuzz();
  14. for (int i = 1; i <=100; i++){
  15. System.out.println(fiz.getOutput(i));
  16. }
  17. }
  18. public String getOutput(int i){
  19. if (i % 5 == 0 && i % 3 == 0){
  20. return "FizzBuzz";
  21. }
  22. else if (i % 3 == 0){
  23. return "Fizz";
  24. }
  25. else if (i % 5 == 0){
  26. return "Buzz";
  27. }
  28. else{
  29. return i + "";
  30. }
  31. }
  32. }
Add Comment
Please, Sign In to add comment