I am trying to create a piece of code for the game 'fizzbuzz', if n|3 => n=Fizz, if n|5 => n= Buzz and if n|3 and n|5 then n=Fizzbuzz.
For some reason my code only displays 46 lines of code, can someone help me out? Thanks.
Here is my code:
import static java.lang.Math.*;
import java.io.*;
public class P2InventedExercise
{
static void FizzBuzz(int n)
{
/** Welcome Message **/
System.out.println("+----------------------------+");
System.out.println("| WELCOME TO FIZZ BUZZ |");
System.out.println("+----------------------------+");
/** Creating Strings to Print & Defines integer 'k'. **/
String Fizz = "Fizz";
String Buzz = "Buzz";
String FizzBuzz = "FizzBuzz";
int k = 0;
/** Printing Strings **/
while (k <= n)
{
/** Boolean Tests **/
boolean FizzTest = (k%3 == 0);
boolean BuzzTest = (k%5 == 0);
boolean FizzBuzzTest = (k%3 == 0 && k%5 == 0);
/** If Tests **/
if (FizzBuzzTest)
{
System.out.println(k+"= " + FizzBuzz);
k=k+1;
continue;
}
if (FizzTest)
{
System.out.println(k + "= " + Fizz);
k=k+1;
continue;
}
else if (BuzzTest)
{
System.out.println(k + "= " + Buzz);
k=k+1;
continue;
}
else
{
System.out.println(k + "= " + k);
k=k+1;
continue;
}
}
}
}