Monday, August 31, 2009

FizzBuzz Challenge!

This is my FizzBuzz program that I wrote. It took me about 10 minutes from opening java to write verify and implement the code. It was a little funny working on this program because I forgot about the system.out part before putting println. This annoyed me, since i wasted a couple of minutes wondering why it didn't work, but realized that mistake. But other than that small hickup, everything else went smoothly.

//This program Is the fizzbuzz program that prints the numbers
//from 1-100 And prints "fizz" In place of the number If the number Is a factor of 3 And
//prints "buzz" In place of the number If the number Is a factor of 5 And prints
//"fizzbuzz" In place of the number If the number Is a factor of both 3 And 5.
Public class FizzBuzz {
Public Static void main(String[] args){
//main Loop To go through all the numbers from 1-100
For(int i=1;i<=100;i++){
If(i%15 == 0){
//If a factor of both 3 And 5 Print fizzbuzz
System.out.println
("FizzBuzz");
}Else If(i%3 == 0){
//If a factor of 3 Print fizz
System.out.println
("Fizz");
}Else If(i%5 == 0){
//If a factor of 5 Print buzz
System.out.println
("Buzz");
}Else{
//If Not a factor of 3 Or 5, Print number
System.out.println
(i);
}
}
}
}



0 comments:

Post a Comment