FizzBuzz problem

I tried to solve the FizzBuzz problem! I feel like it's more refreshing, but I'll try to solve it again.

FizzBuzz problem

Integers from 1 to 100 are output to the screen in order.

However, "Fizz" is output for multiples of 3, "Buzz" for multiples of 5, and "FizzBuzz" for multiples of 3 and 5 on the screen instead of numbers.



public class FizzBuzz {
    public static void main(String[] args) {
        for (int i = 1; i <= 100; i++) {  //Loop with a number from 1 to 100 with for(① Initialization formula;② Conditional expression;④ Iterative)
            //In iterative formula, write the process you want to do after iterative(When repeating, i is always+1 to be)
            if (i % 3 == 0) {
                //When it is a multiple of 3 and a multiple of 5
                if (i % 5 == 0) {
                    System.out.println("FizzBuzz");
                    //When it is a multiple of 3
                } else {
                    System.out.println("Fizz");
                }
            } else if (i % 5 == 0) {  //When it is a multiple of 5
                System.out.println("Buzz");
                //If none of the above apply
            } else {
                System.out.println(i);
            }
        }
    }
}

Recommended Posts

FizzBuzz problem
[Ruby] FizzBuzz problem
[Ruby] FizzBuzz problem
Explanation of the FizzBuzz problem
Let's solve the FizzBuzz problem!
I tried the FizzBuzz problem
[N + 1 problem]
FizzBuzz various
A memorandum of the FizzBuzz problem
Ruby problem ⑦
Expression used in the fizz_buzz problem
Implement FizzBuzz problem in test-driven development (preparation)
ruby API problem
Object-oriented FizzBuzz (Java)
scan method problem
Google recruit problem
[Java] Problem No. 2
[Java] Problem No.3
[Ruby] Ruby API problem
ruby API problem
[Java] Problem No.1
Ruby_work basic problem
I tried FizzBuzz.
FizzBuzz program (2 types)
FizzBuzz in Java
Try to solve a restricted FizzBuzz problem in Java