別のプログラミング言語に変換するGPTs
Python
def fizzbuzz(n): for i in range(1, n+1): if i % 3 == 0 and i % 5 == 0: print("FizzBuzz") elif i % 3 == 0: print("Fizz") elif i % 5 == 0: print("Buzz") else: print(i) # Example usage fizzbuzz(15)
- 以下Pythonから他言語に変換
Translate this Python code to XXX
Java
public class FizzBuzz { public static void fizzbuzz(int n) { for (int i = 1; i <= n; 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); } } } public static void main(String[] args) { fizzbuzz(15); // Example usage } }
Go
package main import "fmt" func fizzBuzz(n int) { for i := 1; i <= n; i++ { if i % 3 == 0 && i % 5 == 0 { fmt.Println("FizzBuzz") } else if i % 3 == 0 { fmt.Println("Fizz") } else if i % 5 == 0 { fmt.Println("Buzz") } else { fmt.Println(i) } } } func main() { fizzBuzz(15) }
JS
function fizzBuzz(n) { for (let i = 1; i <= n; i++) { let output = ''; if (i % 3 === 0) output += 'Fizz'; if (i % 5 === 0) output += 'Buzz'; console.log(output || i); } } fizzBuzz(15);
TypeScript
function fizzBuzz(n: number): void { for (let i = 1; i <= n; i++) { let output = ''; if (i % 3 === 0) output += 'Fizz'; if (i % 5 === 0) output += 'Buzz'; console.log(output || i); } } fizzBuzz(15);
Ruby
def fizz_buzz(n) (1..n).each do |i| if i % 3 == 0 && i % 5 == 0 puts 'FizzBuzz' elsif i % 3 == 0 puts 'Fizz' elsif i % 5 == 0 puts 'Buzz' else puts i end end end fizz_buzz(15)
Kotlin
fun fizzBuzz(n: Int) { for (i in 1..n) { when { i % 3 == 0 && i % 5 == 0 -> println("FizzBuzz") i % 3 == 0 -> println("Fizz") i % 5 == 0 -> println("Buzz") else -> println(i) } } } fun main() { fizzBuzz(15) }
PHP
<?php function fizzBuzz($n) { for ($i = 1; $i <= $n; $i++) { if ($i % 3 == 0 && $i % 5 == 0) { echo "FizzBuzz\n"; } elseif ($i % 3 == 0) { echo "Fizz\n"; } elseif ($i % 5 == 0) { echo "Buzz\n"; } else { echo $i . "\n"; } } } fizzBuzz(15);
C sharp
using System; class Program { static void FizzBuzz(int n) { for (int i = 1; i <= n; i++) { if (i % 3 == 0 && i % 5 == 0) { Console.WriteLine("FizzBuzz"); } else if (i % 3 == 0) { Console.WriteLine("Fizz"); } else if (i % 5 == 0) { Console.WriteLine("Buzz"); } else { Console.WriteLine(i); } } } static void Main() { FizzBuzz(15); } }