Saturday, January 17, 2015

Fizz Buzz using Java and recursion

My very first little program in Eclipse :) It's honestly kinda the same as the C# would be, except printing is different. Very fun though! I am so excited to work in Java too now. Seeing things work without errors makes me very, very happy!!! :D

public class Puzzle 
{
    int i = 0;
 
    public void fizzBuzz()
    {
         i++;

         if (i % 15 == 0) System.out.println("fizz buzz");
         else if (i % 3 == 0) System.out.println("fizz");
         else if (i % 5 == 0) System.out.println("buzz");
         else System.out.println(i);
     
         if (i <= 100) fizzBuzz();
    }
}

public class App 
{ 
    public static void main( String[] args )
    {
         Puzzle fizzeh = new Puzzle();
         fizzeh.fizzBuzz();
    }
   
}