Skip to content

Instantly share code, notes, and snippets.

@kawakawa
Created July 12, 2014 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawakawa/4bcab29a9e8d39c10003 to your computer and use it in GitHub Desktop.
Save kawakawa/4bcab29a9e8d39c10003 to your computer and use it in GitHub Desktop.
DartでFizzBuzz
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);
}
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