From 6fbac74dcea6ae3fbc9acd405f7986f03431efc6 Mon Sep 17 00:00:00 2001 From: Dimitar Mavrodiev Date: Wed, 19 Oct 2016 12:04:36 +0300 Subject: [PATCH] FizzBuzz interview problem. --- src/TechInterview/FizzBuzz.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/TechInterview/FizzBuzz.java diff --git a/src/TechInterview/FizzBuzz.java b/src/TechInterview/FizzBuzz.java new file mode 100644 index 0000000..29fc888 --- /dev/null +++ b/src/TechInterview/FizzBuzz.java @@ -0,0 +1,22 @@ +/* + * Write a Java program that prints the numbers from 1 to 50. + * 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" + */ +package TechInterview; + +public class FizzBuzz { + public static void main(String args[]) { + for (int i = 1; i <= 50; i++) { + if (i % (3 * 5) == 0) { + System.out.println("FizzBuzz"); + } else if (i % 5 == 0) { + System.out.println("Buzz"); + } else if (i % 3 == 0) { + System.out.println("Fizz"); + } else { + System.out.println(i); + } + } + } +}