41 lines
968 B
Java
41 lines
968 B
Java
class fizzbuzz
|
|
{
|
|
private static void fizzBuzz(int n)
|
|
{
|
|
for (int i = 1; i <= n; i++)
|
|
{
|
|
if (i%3 == 0 || i%5 == 0)
|
|
{
|
|
if (i%3 == 0)
|
|
System.out.print("fizz");
|
|
if (i%5 == 0)
|
|
System.out.print("buzz");
|
|
}
|
|
else
|
|
{
|
|
System.out.print(i);
|
|
}
|
|
System.out.println("");
|
|
}
|
|
}
|
|
|
|
// Your program begins with a call to main().
|
|
// Prints "Hello, World" to the terminal window.
|
|
public static void main(String args[])
|
|
{
|
|
System.out.print("How many fizzbuzzes?: ");
|
|
String input = System.console().readLine();
|
|
|
|
try
|
|
{
|
|
int n = Integer.parseInt(input);
|
|
fizzBuzz(n);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
System.out.println("Invalid input");
|
|
return;
|
|
}
|
|
}
|
|
}
|