言語別FizzBuzz【随時更新】

書ける言語で **FizzBuzz** 書いてみた。
(今後も書ける言語増えたら追加するかも)

## Java

記：2017/10/04

```java
import java.util.ArrayList;
import java.util.List;
public class FizzBuzz {
	public static void main(String[] args) {
		int start = 1;
		int end   = 100;
		List<String> fizzBuzz = new ArrayList<>();
		for (int i = start; i < end; i++) {
			String str = "";
			if (i % 3 == 0) {
				str += "Fizz";
			}
			if (i % 5 == 0) {
				str += "Buzz";
			}
			if (str == "") {
				str = String.valueOf(i);
			}
			fizzBuzz.add(str);
		}
		System.out.println(fizzBuzz);
	}
}
```

```
[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz]
```

業務でも使ってたから、割とすんなり書けた。


## Python

記：2017/10/04

```python
start = 1
end   = 100
fizz_buzz = []
for i in range(start, end + 1):
    str = ''
    if i % 3 == 0:
        str += 'Fizz'
    if i % 5 == 0:
        str += 'Buzz'
    if str == '':
        str = i
    fizz_buzz.append(str)
print (fizz_buzz)
```

```
[1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', 16, 17, 'Fizz', 19, 'Buzz', 'Fizz', 22, 23, 'Fizz', 'Buzz', 26, 'Fizz', 28, 29, 'FizzBuzz', 31, 32, 'Fizz', 34, 'Buzz', 'Fizz', 37, 38, 'Fizz', 'Buzz', 41, 'Fizz', 43, 44, 'FizzBuzz', 46, 47, 'Fizz', 49, 'Buzz', 'Fizz', 52, 53, 'Fizz', 'Buzz', 56, 'Fizz', 58, 59, 'FizzBuzz', 61, 62, 'Fizz', 64, 'Buzz', 'Fizz', 67, 68, 'Fizz', 'Buzz', 71, 'Fizz', 73, 74, 'FizzBuzz', 76, 77, 'Fizz', 79, 'Buzz', 'Fizz', 82, 83, 'Fizz', 'Buzz', 86, 'Fizz', 88, 89, 'FizzBuzz', 91, 92, 'Fizz', 94, 'Buzz', 'Fizz', 97, 98, 'Fizz']
```

最近勉強してるから、割とすんなり書けた。


## Ruby

記：2017/10/04

```ruby

start = 1
endx   = 100
fizz_buzz = []
for i in start..endx do
    str = ''
    if i % 3 == 0 then
        str += 'Fizz'
    end
    if i % 5 == 0 then
        str += 'Buzz'
    end
    if str == ''
        str = i
    end
    fizz_buzz.push(str)
end
p fizz_buzz
```

```
[1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz", "Fizz", 52, 53, "Fizz", "Buzz", 56, "Fizz", 58, 59, "FizzBuzz", 61, 62, "Fizz", 64, "Buzz", "Fizz", 67, 68, "Fizz", "Buzz", 71, "Fizz", 73, 74, "FizzBuzz", 76, 77, "Fizz", 79, "Buzz", "Fizz", 82, 83, "Fizz", "Buzz", 86, "Fizz", 88, 89, "FizzBuzz", 91, 92, "Fizz", 94, "Buzz", "Fizz", 97, 98, "Fizz", "Buzz"]
```

しばらく触ってなかったから、クラス定義/メソッド定義とか忘れてた。


## Go

記：2017/10/04

```go
package main
import (
    "log"
    "strconv"
)

func main(){
    var start int = 1
    var end   int = 100
    var fizzBuzz []string
    for i := start; i < end; i++ {
        var str string = ""
        if i % 3 == 0 {
            str += "Fizz"
        }
        if i % 5 == 0 {
            str += "Buzz"
        }
        if str == "" {
            str = strconv.Itoa(i)
        }
        fizzBuzz = append(fizzBuzz, str)
    }
    log.Println(fizzBuzz)
}
```

```
2017/09/25 13:20:14 [1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz]
```

業務でやりかけて、結局ほとんど触ってないから、調べながら何とか...


## JavaScript

記：2019/07/17

```js
var start = 1;
var end   = 100;
var fizzBuzz = [];
for (var i = start; i <= end; i++) {
    var str = "";
    if (i % 3 == 0) {
        str += "Fizz";
    }
    if (i % 5 == 0) {
        str += "Buzz";
    }
    if (str == "") {
        str = i;
    }
    fizzBuzz.push(str);
}
console.log(fizzBuzz);
```

```
[1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz", "Fizz", 52, 53, "Fizz", "Buzz", 56, "Fizz", 58, 59, "FizzBuzz", 61, 62, "Fizz", 64, "Buzz", "Fizz", 67, 68, "Fizz", "Buzz", 71, "Fizz", 73, 74, "FizzBuzz", 76, 77, "Fizz", 79, "Buzz", "Fizz", 82, 83, "Fizz", "Buzz", 86, "Fizz", 88, 89, "FizzBuzz", 91, 92, "Fizz", 94, "Buzz", "Fizz", 97, 98, "Fizz", "Buzz"]
```

JavaScriptは書きやすい、、、


## C＃

記：2019/07/17

```csharp
public class FizzBuzz
{
    static void Main(string[] args)
    {
        var start = 1;
        var end = 100;
        var fizzBuzz = new System.Collections.Generic.List<string>();
        for (var i = start; i <= end; i++)
        {
            var str = "";
            if (i % 3 == 0)
            {
                str += "Fizz";
            }
            if (i % 5 == 0)
            {
                str += "Buzz";
            }
            if (str == "")
            {
                str = i.ToString();
            }
            fizzBuzz.Add(str);
        }
        System.Console.WriteLine(string.Join(", ", fizzBuzz.ToArray()));
    }
}
```

```
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz
```

Javaと似てて書きやすい。


## ShellScript

記：2019/07/17

```sh
#!/usr/bin/bash
start=1
end=100
fizzBuzz=()
for i in $(seq $start $end)
do
    str=""
    if [ $((i % 3)) -eq 0 ]; then
        str="${str}Fizz"
    fi
    if [ $((i % 5)) -eq 0 ]; then
        str="${str}Buzz"
    fi
    if [ -z "$str" ]; then
        str=$i
    fi
    fizzBuzz+=($str)
done
echo ${fizzBuzz[@]}
```

```
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz
```

Shell芸人になりたい。

## PowerShell

記：2019/07/17

```powershell
$start = 1
$end   = 100
$fizzBuzz = @()
for ($i = $start; $i -le $end; $i++)
{
    $str = "";
    if ($i % 3 -eq 0)
    {
        $str += "Fizz";
    }
    if ($i % 5 -eq 0)
    {
        $str += "Buzz";
    }
    if ($str -eq "")
    {
        $str = $i;
    }
    $fizzBuzz += $str;
}
$fizzBuzz -join ", "
```

```
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz
```

クセが凄い。(cv. 千鳥ノブ)


## Julia

記：2019/07/17

```julia
_start = 1
_end   = 100
fizz_buzz = Any[]
for i in _start:_end
	str = ""
	if i % 3 == 0
		str *= "Fizz"
	end
	if i % 5 == 0
		str *= "Buzz"
	end
	if str == ""
		str = i
	end
	push!(fizz_buzz, str)
end
println(fizz_buzz)
```

```
Any[1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz", "Fizz", 52, 53, "Fizz", "Buzz", 56, "Fizz", 58, 59, "FizzBuzz", 61, 62, "Fizz", 64, "Buzz", "Fizz", 67, 68, "Fizz", "Buzz", 71, "Fizz", 73, 74, "FizzBuzz", 76, 77, "Fizz", 79, "Buzz", "Fizz", 82, 83, "Fizz", "Buzz", 86, "Fizz", 88, 89, "FizzBuzz", 91, 92, "Fizz", 94, "Buzz", "Fizz", 97, 98, "Fizz", "Buzz"]
```

流行りそうだから書いてみた。
文字列結合が`*=`とか、配列追加が`push!(arr, val)`とか、慣れるまで時間かかりそう、、、


## まとめ

同じ事をやってても、言語によって書き方違うから面白い！！！

プログラミングは面白い！！！(大声)