There is no particular meaning Let's write up to 20 FizzBuzz in various languages without using "="
c_fizzbuzz.c
#include <stdio.h>
int main(void) {
int n;
n++;
while (1) {
if (n%3 && n%5) {
printf("%d", n);
}
else{
if (!(n%3)) {
printf("Fizz");
}
if (!(n%5)) {
printf("Buzz");
}
}
printf("\n");
n++;
if (n>20) {
break;
}
}
return 0;
}
Use that 0 is entered if not initialized (however, depending on the compiler) Conditional branch using the property that 0 is False and the others are True
Python
python_fizzbuzz.py
def fizzbuzz(n):
if n%3 and n%5:
return n
else:
if not n%3 and not n%5:
return "FizzBuzz"
elif not n%3:
return "Fizz"
elif not n%5:
return "Buzz"
for x in list(map(fizzbuzz, range(1,21))):
print(x)
Because Python has no increments Create a list of integers with range In the method of multiplying all functions at once with map Sober
print("hoge", end="")
It was hard because I couldn't use
Java
java_fizzbuzz.java
class java_fizzbuzz {
static int n;
public static void main(String[] args) {
n++;
while(true){
if (!String.valueOf(n%3).equals("0") && !String.valueOf(n%5).equals("0")) {
System.out.print(n);
}
else{
if (String.valueOf(n%3).equals("0")) {
System.out.print("Fizz");
}
if (String.valueOf(n%5).equals("0")) {
System.out.print("Buzz");
}
}
System.out.println();
n++;
if (n>20) {
break;
}
}
}
}
Take advantage of class member variables being initialized with 0 It turns out that Boolean is not processed with 0 or other By converting to String once and comparing with equals, it was not necessary to use equals
Please refer to it when you really do not want to use "=" Let's initialize the variables explicitly
There is a better way to write! You can do this in this language! If you have any questions, please leave a comment.
Recommended Posts