Created
February 22, 2015 17:42
-
-
Save steventhanna/8d71e21da7d5f70fe9d4 to your computer and use it in GitHub Desktop.
The FizzBuzz Test in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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(""); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment