Skip to content

Instantly share code, notes, and snippets.

@gauravbansal74
Created January 13, 2018 07:18
Show Gist options
  • Save gauravbansal74/577cee8546f515dfd1ba13eb4ee69fd2 to your computer and use it in GitHub Desktop.
Save gauravbansal74/577cee8546f515dfd1ba13eb4ee69fd2 to your computer and use it in GitHub Desktop.
FizzBuzz
class FizzBuzz {
public static void solution(int N) {
// write your code in Java SE 8
int count = 0;
int contCount = 0;
for(int i = 1; i<=N;i++){
if((i % 3 == 0) && (i % 5 == 0) && (i % 7 == 0)){
System.out.println("FizzBuzzWoof");
}
else if((i % 3 == 0) && (i % 5 == 0)){
contCount++;
if(contCount%2 == 0){
System.out.println("FizzWoof");
}
else{
System.out.println("FizzBuzz");
}
}
else if((i % 3 == 0) && (i % 7 == 0)){
contCount++;
if(contCount%2 == 0){
System.out.println("FizzWoof");
}
else{
System.out.println("FizzBuzz");
}
}
else if((i % 5 == 0) && (i % 7 == 0)){
contCount++;
if(contCount%2 == 0){
System.out.println("FizzWoof");
}
else{
System.out.println("FizzBuzz");
}
}
else if( (i % 3 == 0) || (i % 5 == 0) || (i % 7 == 0)){
count++;
if(count%2 == 0 && count%4 != 0){
System.out.println("Buzz");
}
else if(count % 4 == 0){
System.out.println("Woof");
}
else{
System.out.println("Fizz");
}
}
else{
System.out.println(i);
}
}
}
public static void main(String[] args){
solution(105);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment