Advertisement
BanditMcDougal

Bad FizzBuzz

Mar 26th, 2015
8,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. /*
  2. *   Write a method that prints the numbers from 1 to 100.
  3. *       For multiples of 3 print “Fizz” instead of the number
  4. *       For the multiples of 5 print “Buzz”.
  5. *       For numbers which are multiples of both 3 and 5 print “FizzBuzz”."
  6. *   1
  7. *   2
  8. *   Fizz
  9. *   4
  10. *   Buzz
  11. *   Fizz
  12. *   7
  13. *   8
  14. *   Fizz
  15. *   Buzz
  16. *   11
  17. *   Fizz
  18. *   13
  19. *   14
  20. *   FizzBuzz
  21. */
  22.  
  23. /*
  24. *   I have no idea what this candidate was trying to do.  Swore division was the right way to go even after
  25. *   we moved the conversation away from code and just made it about math.  Left formatting as was given to us.
  26. */
  27. for( int i= 1 ; i<= 100; i++)
  28. {
  29.     Boolean j =( i/3 != 0)
  30.         (Boolean k =( i/5 != 0))
  31.    
  32.         print (i)
  33.     if ( j == 0)
  34.         { print( "Fizz")
  35.    
  36.         if (j ==  0)
  37.             { print i);)
  38.        
  39.         if ( k == 0)
  40.             print (" Buzz")        
  41. }
  42.  
  43. /*
  44. *       A much better attempt by another candidate.  Not a horrible effort.  Some syntax issues I'll forgive
  45. *   and a logic issue that may or may not have been found while walking through it: FizzBuzz will never
  46. *   get printed as written.
  47. */
  48.  
  49. for (int i = 1; i <= 100; i ++)
  50. {
  51.     if i % 3 = 0
  52.     (
  53.         Console.WriteLine("Fizz")
  54.         )
  55.         else i % 5 = 0
  56.         (
  57.                 Console.WriteLine("Buzz)
  58.         )
  59.         else (i % 3 = 0 && i % 5 = 0 )
  60.         (
  61.                Console.Write("FizzBuzz")
  62.         )
  63.         elseif
  64.         (
  65.             Console.WriteLine(i)
  66.         )
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement