Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.script47.fizzbuzz;
- /**
- * The different FizzBuzz test types.
- *
- * @author Script47
- * @coyright 2014, Script47
- * @version 1.1.0
- *
- * 27/10/2014
- */
- public class Main {
- public static String checkFizzBuzz(String string) {
- if(string.toLowerCase().startsWith("f") && string.toLowerCase().endsWith("b")) {
- return string + " - FizzBuzz";
- } else if(string.toLowerCase().startsWith("f")) {
- return string + " - Fizz";
- } else if(string.toLowerCase().endsWith("b")) {
- return string + " - Buzz";
- }
- return string;
- }
- public static void generateFizzBuzz() {
- // Generate numbers from 1-100
- for(int i = 1; i <= 100; i++) {
- // Check if i (the generated number variable) has a remainder (% - modulus finds the remainder) of the specified number in this case 3/5.
- if(i % 3 == 0 && i % 5 == 0) {
- System.out.println(i + " - FizzBuzz");
- // Check for 3 only.
- } else if(i % 3 == 0) {
- System.out.println(i + " - Fizz");
- // Check for 5 only.
- } else if(i % 5 == 0) {
- System.out.println(i + " - Buzz");
- }
- }
- }
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement