Skip to content

Instantly share code, notes, and snippets.

@dmnugent80
Created January 30, 2015 23:20
Show Gist options
  • Save dmnugent80/6b3343615d9c7c82a091 to your computer and use it in GitHub Desktop.
Save dmnugent80/6b3343615d9c7c82a091 to your computer and use it in GitHub Desktop.
FizzBuzz
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
try{
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int N = Integer.parseInt(line);
for (int i = 1; i <= N; i++) {
if (i % 3 == 0 && i % 5 == 0){
System.out.println("FizzBuzz");
}
else if (i % 3 == 0){
System.out.println("Fizz");
}
else if (i % 5 == 0){
System.out.println("Buzz");
}
else{
System.out.println(i);
}
}
}
catch(Exception e){
System.out.println("Exception thrown :" + e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment