Recently I started looking for a new role, a new developer role. During my interviews, I have come across a number of questions and coding challenges. For each of these challenges, I take my time, create the code. I then come home and revisit that challenge to write a better solution.

Recently I started looking for a new role, a new developer role. During my interviews, I have come across a number of questions and coding challenges. For each of these challenges, I take my time, create the code. I then come home and revisit that challenge to write a better solution.

In this new solution I create it in a few different languages, just to challenge myself, but to also provide my solution to anyone who maybe looking for the solution the this quiz question.

For this challenge I take one of the common coding quizzes I've seen asked during an interview is the FizzBuzz code question.

FizzBuzz

What is FizzBuzz? Simply put, its a challenge that will print one of 3 words when a number is divisible by a given number, and if not divisible it will output the number.

So, it seems common to give the following parameters:

  1. Number range is 1 to 100
  2. If the number is divisible by 3 then output Fizz
  3. If the number is divisible by 5 then output Buzz
  4. If the number is divisible by 3 and 5 then output Fizzbuzz
  5. If the number is not divisible by the above values, output the value

FizzBuzz in Java

Given the above parameters, here is my solution for this FizzBuzz challenge written in Java



public class FizzBuzz {   public static void main(String[] args) {    boolean foundVal = false;      int count;      for(count = 1; count <= 100; count++)   {    if (count%3 == 0) {     System.out.print("Fizz");      foundVal = true;    }    if (count%5 == 0) {     System.out.print("Buzz");      foundVal = true;    }    if (foundVal) System.out.println("");    if (!foundVal) System.out.println(count);        foundVal = false;       }  }  }
Sean

Share
Published by
Sean

Recent Posts

What Is The Difference Between A Singleton Class And Dependency Injection

A singleton class is a design pattern where only one instance of a class can…

11 months ago

Dependency Injection In Java Explained With Code Example

As one of the most popular programming languages, Java has played a vital role in…

11 months ago

Are There So Many Bad C/C++ Developers Out There Today?

I was taking a look at Quora, something I try to do daily, and while…

12 months ago

Why I Deleted Windows And Installed Only Linux

I finally did it, I completely deleted Windows from my Laptop and installed Linux.  Let…

12 months ago

Why Are Graphics Cards So Expensive At The Moment?

Recently I've been building a new mid-level gaming system for my daughter, and although most…

2 years ago

How to balance work and family life

In order to balance work and family life, one must find the right work-life balance…

3 years ago