Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Author: Yong Hong Hsu
- //The FizzBuzz program try to pirnt out number from 1 to 100, except when the number
- //is multiple of 3, 5 and both 3 and 5
- //Date: 8/29/11
- //Time of finishedd: 10 mins
- public class FizzBuzz {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- FizzBuzz fiz = new FizzBuzz();
- for (int i = 1; i <=100; i++){
- System.out.println(fiz.getOutput(i));
- }
- }
- public String getOutput(int i){
- if (i % 5 == 0 && i % 3 == 0){
- return "FizzBuzz";
- }
- else if (i % 3 == 0){
- return "Fizz";
- }
- else if (i % 5 == 0){
- return "Buzz";
- }
- else{
- return i + "";
- }
- }
- }
Add Comment
Please, Sign In to add comment