The purpose of this program is to print integers from 1 - 100 with the following exception, every number divisible by 3 prints Fizz, 5 prints Buzz, 3 and 5 prints FizzBuzz. It was assigned to test
"programmers", who say they can program, but in reality they can not. This simple program helped companies to not hire people who can not do a simple program.
Time took to do this: 5 min
Problems: A little basics
Solutions: Look for examples online or the java API
Overview:
Fun refresher when done in class. It was interesting to learn the JUnit test case program and implementing it with this program. So far the class seems great. Love the structure of how we are doing work in class and not mostly at home.
Code:
public class FizzBuzz {
//Constructor to print out the numbers.
public FizzBuzz(){
for(int x = 1; x <= 100; x++){ if((x % 15) == 0){//number is 15 because that is 3 and 5 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); } } }
public static void main(String[]args){
FizzBuzz fizzer = new FizzBuzz();
}
No comments:
Post a Comment