Skip to content

Instantly share code, notes, and snippets.

@koduki
Created June 7, 2009 10:08
Show Gist options
  • Save koduki/125259 to your computer and use it in GitHub Desktop.
Save koduki/125259 to your computer and use it in GitHub Desktop.
// ifによる記述
String x;
if(n % 15 == 0){
x = "FizzBuzz";
}else if(n % 5 == 0){
x = "Fizz";
}else if(n % 3 == 0){
x = "Buzz";
}else{
x = x.toString();
}
// 3項演算子による記述
String x = (n % 15 == 0) ? "FizzBuzz"
:(n % 5 == 0) ? "Fizz"
:(n % 3 == 0) ? "Buzz"
: x.toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment