Created
October 15, 2012 07:20
-
-
Save KazumasaSUGAYA/3891180 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
【内容】 | |
最小値(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