[JAVA] Write FizzBuzz without using "="

I want to write FizzBuzz without using "="

There is no particular meaning Let's write up to 20 FizzBuzz in various languages without using "="

C language

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

Summary

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

Write FizzBuzz without using "="
Modulo without using%
Write test-driven FizzBuzz code using Python doctest.
Write FizzBuzz using map (), reduce (), filter (), recursion
Bubble sort without using sort
Quicksort without using sort
Gamma correction without using OpenCV
poor man's fizzbuzz using srcgen
[Python3] Google translate google translate without using api
Achieve enumeration modoki without using enum
Slice without using Python, colon (:). a.__getitem__ (slice (3,5)).
Write Ethereum contract code using Serpent
Save files using EC2 storage without using S3
Implement OAuth without using client library (Java)
Swap 1 and 2 without using an if statement
Use webcam without screen display using python-zbar
Write python modules in fortran using f2py
Merge Sort Explained
Bubble sort without using sort
Quicksort without using sort
Recursion
sort
Write FizzBuzz using map (), reduce (), filter (), recursion