Created
August 17, 2015 06:09
-
-
Save masakid/a798d5fbd70737fee743 to your computer and use it in GitHub Desktop.
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
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