FizBuzz program: how to make the output correct?

后端 未结 4 382
梦谈多话
梦谈多话 2021-01-24 15:51

I got a question about this program, it says: The FizzBuzz Challenge: Display numbers from 1 to x, replacing the word \'fizz\' for multiples of 3, \'buzz\' for multiples

4条回答
  •  失恋的感觉
    2021-01-24 16:44

    Here's the pseudocode:

    for i in 1 to 100
       if(i % 5 == 0) AND (i % 3 == 0) print 'fizzbuzz'
       else if(i % 3 == 0) print 'fizz'
       else if(i % 5 == 0) print 'buzz'
       else print i
    

    I'll leave it as an exercise for you to convert it into Java, as that might help with the understanding as to how this works.

提交回复
热议问题