Skip to content

Instantly share code, notes, and snippets.

@steventhanna
Created February 22, 2015 17:42
Show Gist options
  • Select an option

  • Save steventhanna/8d71e21da7d5f70fe9d4 to your computer and use it in GitHub Desktop.

Select an option

Save steventhanna/8d71e21da7d5f70fe9d4 to your computer and use it in GitHub Desktop.

Revisions

  1. steventhanna created this gist Feb 22, 2015.
    30 changes: 30 additions & 0 deletions FizzBuzz.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    /**
    * @author Steven T Hanna
    * @class FizzBuzz
    * @date 2/22/15
    * @description Complete the FizzBuzz test in Java
    */

    public class FizzBuzz {

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

    for(int i = 0; i <= 100; i++) {
    if((i % 3 == 0) || (i % 5 == 0)) {
    if(i % 3 == 0) {
    System.out.print("Fizz");
    }
    if(i % 5 == 0) {
    System.out.print("Buzz");
    }
    } else {
    System.out.print(i);
    }
    System.out.println("");
    }
    }
    }