first commit
This commit is contained in:
40
FizzBuzz/Java/fizzbuzz.java
Normal file
40
FizzBuzz/Java/fizzbuzz.java
Normal file
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user