Wednesday, August 31, 2011

The implementation of the FizzBuzz program took me about 10 minutes to implement.
Most of the time could be attributed to the fact that I had never really used eclipse before, and had a little
trouble seting up the workspace correctly.  Another reason why it took me a little longer was that I had to
remember how to program in Java becuase it has beena while since the last time I programmed in Java.
however, once I remembered the format it was relatively quick to get it working and obtain an output.
I had to make a slight adjustment to my original algorithm because ot was testing and printing the case of 3 before it
reached the case of 3 and 5 multiples.  So the fix was to put that test case before the test of 3.
package edu.hawaii;

Program:
public class FizzBuzz {
    public static void main (String [] args){
   
    for(int x = 1; x < 101; x++){
     if ((x % 3 == 0)&&(x % 5 == 0)){
            System.out.println("FIZZBUZZ");
        }
     else if (x % 3 == 0){
        System.out.println("FIZZ");
        }
    else if (x % 5 == 0){
        System.out.println("BUZZ");
    }
    else{
        System.out.println(x);
    }
        }
    }
}

No comments:

Post a Comment