fizzbuzz

FizBuzz program: how to make the output correct?

∥☆過路亽.° 提交于 2019-12-02 05:35:37
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 of 5 and 'fizzbuzz' for multiples of both 3 and 5. Th result must be:1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz 16 ... So my problem is at the time to print the output, I dont know what to do. public class Multiplos { public static void main(String args[]) { for (int i = 1; i <= 100; i++) { if (i % 3 == 0) { System.out.print(i + " "); System.out.print(" fizz "); } if (i % 5 == 0) { System.out.print(" " + i); System

Python Fizzbuzz problems with loop

狂风中的少年 提交于 2019-12-02 03:04:59
I've searched for the answer for about an hour, and it seems most people have coded fizzbuzz a different way than myself. However, having tried everything to figure out why this simple code will not work I'm getting extremely frustrated. Can anyone point out the simple problem I'm sure I'm having? The code runs but it just returns the value 1. def fizzbuzz(intList): for n in intList: if n % 3 == 0 and n % 5 == 0: return n.replace(str(n),"Fizzbuzz") elif n % 3 == 0: return n.replace(str(n),"Fizz") elif n % 5 == 0: return n.replace(str(n),"Buzz") else: return n The first value it looks at is 1 .

javascript fizzbuzz switch statement

◇◆丶佛笑我妖孽 提交于 2019-12-01 18:00:46
I'm currently taking the code academy course on Javascript and I'm stuck on the FizzBuzz task. I need to count from 1-20 and if the number is divisible by 3 print fizz, by 5 print buzz, by both print fizzbuzz, else just print the number. I was able to do it with if/ else if statements, but I wanted to try it with switch statements, and cannot get it. My console just logs the default and prints 1-20. Any suggestions? for (var x = 0; x<=20; x++){ switch(x){ case x%3==0: console.log("Fizz"); break; case x%5===0: console.log("Buzz"); break; case x%5===0 && x%3==0: console.log("FizzBuzz"); break;

Efforts in iteration - FizzBuzz

北城以北 提交于 2019-12-01 14:01:38
EDIT For what its worth, which admittedley may not be that much. I've done a little test to expand this question. I've written two functions to enumerate the FizzBuzz "series." private static IEnumerable<string> SimpleFizzBuzz( int start = 0, int end = int.MaxValue) { return Enumerable.Range(start, end).Select(i => i % 15 == 0 ? "fizzbuzz" : i % 3 == 0 ? "fizz" : i % 5 == 0 ? "buzz" : i.ToString(CultureInfo.InvariantCulture)); } and, private static IEnumerable<string> OptimizedFizzBuzz( int start = 0, int end = int.MaxValue) { const int fizz = 3; const int buzz = 5; const string fizzString =

PHP FizzBuzz Logic

廉价感情. 提交于 2019-12-01 13:41:05
When we write the fizzbuzz script, why are we testing to see if it is equal to 0? Or am I misunderstanding? Example: $i % 3 == 0 <?php for ($i=1; $i<=100; $i++) { if ($i%3==0 && $i%5==0) { echo 'FizzBuzz'; }else if($i%3==0){ echo 'Fizz'; }else if($i%5==0){ echo 'Buzz'; }else{ echo $i; } echo "\n"; } The program fizzbuzz prints 'fizz' if a number is divisible by 3, 'buzz' if a number is divisible by 5, and 'fizzbuzz' if a number is divisible by both. Your program is not checking if the numbers are equal to 0, instead it is using the modulo operator to check if the remainders are 0. $i%3==0

Efforts in iteration - FizzBuzz

久未见 提交于 2019-12-01 12:49:58
问题 EDIT For what its worth, which admittedley may not be that much. I've done a little test to expand this question. I've written two functions to enumerate the FizzBuzz "series." private static IEnumerable<string> SimpleFizzBuzz( int start = 0, int end = int.MaxValue) { return Enumerable.Range(start, end).Select(i => i % 15 == 0 ? "fizzbuzz" : i % 3 == 0 ? "fizz" : i % 5 == 0 ? "buzz" : i.ToString(CultureInfo.InvariantCulture)); } and, private static IEnumerable<string> OptimizedFizzBuzz( int

Alternate FizzBuzz Questions [closed]

∥☆過路亽.° 提交于 2019-11-30 10:04:32
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Anybody have any good FizzBuzz type questions that are not the FizzBuzz problem? I am interviewing someone and FB is relatively well

From 1 to 100, print “ping” if multiple of 3, “pong” if multiple of 5, or else print the number

醉酒当歌 提交于 2019-11-29 23:21:34
I just came home from a job interview, and the interviewer asked me to write a program: It should, count from 1 to 100, and print... If it was multiple of 3, "ping" If it was multiple of 5, "pong" Else, print the number. If it was multiple of 3 AND 5 (like 15), it should print "ping" and "pong". I chose Javascript, and came up with this: for (x=1; x <= 100; x++){ if( x % 3 == 0 ){ write("ping") } if( x % 5 == 0 ){ write("pong") } if( ( x % 3 != 0 ) && ( x % 5 != 0 ) ){ write(x) } } Actualy, I left very unhappy with my solution, but I can't figure out a better one. Does anyone knows a better

Writing FizzBuzz

好久不见. 提交于 2019-11-29 19:27:57
Reading the coding horror, I just came across the FizzBuzz another time. The original post is here: Coding Horror: Why Can't Programmers.. Program? For those who do not know: FizzBuzz is a quite popular childrens game. Counting from 1 to 100, and every time a number is divisible by 3 calling "Fizz", every time a number is divisible by 5 calling "Buzz" and every time a number is divisible by 3 and 5, calling "FizzBuzz instead of the number But this time, I just started to code it down. It was a job of a minute, but there are several things that I do not like. Here is my code public void

Alternate FizzBuzz Questions [closed]

六月ゝ 毕业季﹏ 提交于 2019-11-29 18:35:59
Anybody have any good FizzBuzz type questions that are not the FizzBuzz problem? I am interviewing someone and FB is relatively well known and not that hard to memorize, so my first stop in a search for ideas is my new addiction SO. I've seen a small list of relatively simple programming problems used to weed out candidates, just like FizzBuzz. Here are some of the problems I've seen, in order of increasing difficulty: Reverse a string Reverse a sentence ("bob likes dogs" -> "dogs likes bob") Find the minimum value in a list Find the maximum value in a list Calculate a remainder (given a