Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.myimportantcompany.fizzbuzz;
- /**
- * This is the main class for executing the FizzBuzz Program
- * @author Simon
- *
- */
- public class Main {
- /**
- * This is the main function for the Program, also called the entry point.
- * @param args These are ignored in this program
- */
- public static void main(String[] args) {
- int limitForFizzBuzzProgram = 100;
- for (int forLoopCounter = 0; forLoopCounter <= limitForFizzBuzzProgram; forLoopCounter = forLoopCounter + 1) {
- if(isNumberDivisibleByFiveAndThreeWithoutRemainder(forLoopCounter)) {
- System.out.println(FizzBuzz.FIZZBUZZ);
- } else if(isNumberDivisibleByFiveWithoutRemainder(forLoopCounter)) {
- System.out.println(Buzz.BUZZ);
- } else if(isNumberDivisibleByThreeWithoutRemainder(forLoopCounter)) {
- System.out.println(Fizz.FIZZ);
- } else {
- System.out.println(forLoopCounter);
- }
- }
- }
- /**
- * This function checks whether a given number is divisible by 3 without a remainder
- * @param number the number to be checked
- * @return True if the number is divisible by 3 without a remainder, false otherwise
- */
- public static boolean isNumberDivisibleByThreeWithoutRemainder(int number) {
- if (((number / 3) * 3) == number) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * This function checks whether a given number is divisible by 5 without a remainder
- * @param number the number to be checked
- * @return True if the number is divisible by 5 without a remainder, false otherwise
- */
- public static boolean isNumberDivisibleByFiveWithoutRemainder(int number) {
- if (((number / 5) * 5) == number) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * This function checks whether a given number is divisible by 5 and 3without a remainder
- * @param number the number to be checked
- * @return True if the number is divisible by 5 and 3 without a remainder, false otherwise
- */
- public static boolean isNumberDivisibleByFiveAndThreeWithoutRemainder(
- int number) {
- boolean checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder = false;
- if (((number / 3) * 3) == number) {
- checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder = true;
- } else {
- checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder = false;
- }
- if (((number / 5) * 5) == number) {
- checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder = true;
- } else {
- checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder = false;
- }
- return checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement