Skip to content

Instantly share code, notes, and snippets.

@KazumasaSUGAYA
Created October 15, 2012 07:20
Show Gist options
  • Save KazumasaSUGAYA/3891180 to your computer and use it in GitHub Desktop.
Save KazumasaSUGAYA/3891180 to your computer and use it in GitHub Desktop.
FizzBuzz問題
【内容】
最小値(min)〜最大値(max)までの整数を順番に出力します。
3の倍数だとfizz、5の倍数だとbuzz、 3と5の最小公倍数15の倍数がとfizzbuzzを出力する。
public class FizzBuzz {
public static void main(String[] args) {
int min = 1;
int max = 100;
for (int i = min; i < max + 1; i++) {
if (i % 3 == 0 && i % 5 == 0) {
System.out.println("fizzbuzz");
} else if (i % 3 == 0) {
System.out.println("fizz");
} else if (i % 5 == 0) {
System.out.println("buzz");
} else {
System.out.println(i);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment