FizzBuzz Java

My attempt at the program, took me a bit because i am not used to Java syntax

 

package fizzbuzz;

/**
* @author MM
*/
public class FizzBuzz {

/**
* @param args the command line arguments
*/
public static final int NUM_THREE = 3;
public static final int NUM_FIVE = 5;

public static void main(String[] args) {
// Fizz Buzz
// Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and
//for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.”

for (int i = 1 ; i <= 100; i++) {

if (( i%NUM_THREE == 0) && ( i % NUM_FIVE == 0)) {
System.out.println(“FizzBuzz”);
}
else if ( i%NUM_THREE == 0) {
System.out.println(“Fizz”);
} else if ( i%NUM_FIVE == 0) {
System.out.println(“Buzz”);
} else {
System.out.println(i);
}
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *