Advertisement
Script47

Check FizzBuzz

Oct 27th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package com.script47.fizzbuzz;
  2.  
  3. /**
  4.  * The different FizzBuzz test types.
  5.  *
  6.  * @author Script47
  7.  * @coyright 2014, Script47
  8.  * @version 1.1.0
  9.  *
  10.  * 27/10/2014
  11.  */
  12.  
  13. public class Main {
  14.  
  15.     public static String checkFizzBuzz(String string) {
  16.         if(string.toLowerCase().startsWith("f") && string.toLowerCase().endsWith("b")) {
  17.             return string + " - FizzBuzz";
  18.         } else if(string.toLowerCase().startsWith("f")) {
  19.             return string + " - Fizz";
  20.         } else if(string.toLowerCase().endsWith("b")) {
  21.             return string + " - Buzz";
  22.         }
  23.         return string;
  24.     }
  25.    
  26.     public static void generateFizzBuzz() {
  27.         // Generate numbers from 1-100
  28.         for(int i = 1; i <= 100; i++) {
  29.             // Check if i (the generated number variable) has a remainder (% - modulus finds the remainder) of the specified number in this case 3/5.
  30.             if(i % 3 == 0 && i % 5 == 0) {
  31.                 System.out.println(i + " - FizzBuzz");
  32.                 // Check for 3 only.
  33.             } else if(i % 3 == 0) {
  34.                 System.out.println(i + " - Fizz");
  35.                 // Check for 5 only.
  36.             } else if(i % 5 == 0) {
  37.                 System.out.println(i + " - Buzz");
  38.             }
  39.         }
  40.     }
  41.    
  42.     public static void main(String[] args) {
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement