Skip to content

Instantly share code, notes, and snippets.

@masakid
Created August 17, 2015 06:09
Show Gist options
  • Save masakid/a798d5fbd70737fee743 to your computer and use it in GitHub Desktop.
Save masakid/a798d5fbd70737fee743 to your computer and use it in GitHub Desktop.
FizzBuzzの問題
import java.util.ArrayList;
import java.util.List;
public class FizzBuzzTest {
/**
* 引数の値までのFizzBuzzをList<String>で返却する
* FizzBuzz:
* 3で割り切れるものをFizz
* 5で割り切れるものをBuzz
* 15で割り切れるものをFizzBuzz
* それ以外はその数字
* @param number
* @return
*/
protected static List<String> createFizzBuzzList(Integer number){
//答えのList
List<String> answerList = new ArrayList<>();
//1から与えられた値まで
for(int i=1; i<=number; i++){
if(i%15==0){
answerList.add("FizzBuzz");
} else if(i%3 == 0){
answerList.add("Fizz");
} else if(i%5 == 0){
answerList.add("Buzz");
} else {
answerList.add(String.valueOf(i));
}
}
return answerList;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment