Created
July 12, 2014 05:35
-
-
Save kawakawa/4bcab29a9e8d39c10003 to your computer and use it in GitHub Desktop.
DartでFizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void fb(int n) { | |
if (n == 0) return; | |
fb(n - 1); | |
if(n%15==0){ | |
print("FizzBuzz"); | |
}else if(n%5==0){ | |
print("Buzz"); | |
}else if(n%3==0){ | |
print("Fizz"); | |
}else{ | |
print(n); | |
} | |
} | |
main() { | |
fb(50); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FizzBuzz{ | |
int inpoutVal; | |
String resultVal; | |
FizzBuzz(int n){ | |
this.inpoutVal=n; | |
} | |
void analyze(){ | |
if(inpoutVal%15==0){ | |
resultVal= "FizzBuzz"; | |
}else if(inpoutVal%5==0){ | |
resultVal="Buzz"; | |
}else if(inpoutVal%3==0){ | |
resultVal= "Fizz"; | |
}else{ | |
resultVal= inpoutVal.toString(); | |
} | |
} | |
void render(){ | |
print(resultVal); | |
} | |
} | |
void main(){ | |
var n=0; | |
while(n++ <= 100){ | |
var fb=(new FizzBuzz(n)) | |
..analyze() | |
..render(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment