FizzBuzz Test

Discussion in 'Programming' started by pradeep, May 27, 2009.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Code:
    for(int i = 0 ; i <= 100 ; i++)
    {
    	if(i % 3 == 0 && i % 5 == 0)
    	{ 
    		System.out.println("FizzBuzz"); 
    	}
    	else if(i % 3 == 0)
    	{ 
    		System.out.println("Fizz"); 
    	}
    	else if(i % 5 == 0)
    	{ 
    		System.out.println("Buzz"); 
    	}
    	else
    	{ 
    		System.out.println(i); 
    	}
    }
    
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Heh, well done there. I was trying to put a Brainf*ck one together but gave up after well over 3 hours.
     
  3. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    Thanx ! :happy:

    Programming with Brainf*ck requires a lot of patience. While writing this code, many times it came to me "Why should I write it ?". I was ready to give up, but then I thought I had no better way to utilize my time ! But, BF truely f*cks Brain.
     
    Last edited: Jun 1, 2009
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
  5. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    OMG !!!

    Whitespace, Befunge ! :crazy:
     
  6. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    The program in Mathematica 7 ;)
    Code:
    For[i = 1, i < 101, i++, If[Mod[i, 3] == 0, If[Mod[i, 5] == 0, Print["FIZZBUZZ"], Print["FIZZ"]], If[Mod[i, 5] == 0, Print["BUZZ"], Print[i]]]]
     
  7. Beverly P F

    Beverly P F New Member

    Joined:
    May 9, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Junior Developer
    Location:
    Croatia
    Hi, this is fun :D
    Some languages are missing, here is C#:
    Code:
    for (int i = 1; i <= 100; i++)
    {
        string result = null;
    
        if (i % 3 == 0)
            result += "Fizz";
    
        if (i % 5 == 0)
            result += "Buzz";
    
        Console.WriteLine("{0}", result ?? i.ToString());
    }
    And here is VB.NET:
    Code:
    For i As Integer = 1 To 100
        Dim result As String = Nothing
    
        If i Mod 3 = 0 Then
            result += "Fizz"
        End If
    
        If i Mod 5 = 0 Then
            result += "Buzz"
        End If
    
        Console.WriteLine("{0}", If(result, i.ToString()))
    Next
    Also there is a FizzBuzz enterprise edition on GitHub, I laughed my as* out when I found it :happy::happy::happy:
     
  8. develosapiens

    develosapiens New Member

    Joined:
    May 14, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    It is a very old thread but who cares

    I think it is a good idea to write code in a certain language more than once because as every coder makes a different solution. I am a java programmer and I wrote about fizz buzz game in my blog here: develosapiens.wordpress.com/2015/05/08/fizz-buzz/ I think that code maintenance is more important than the short code. As you can see it in my code -linked before- I created the source in separated files because of easy maintenance requirements. What do you think?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice