Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
Implementation of Sliding window in java
Browse files Browse the repository at this point in the history
This is the java implementation of the sliding window algorithm and modulo operator combination to find the fizz, buzz and fizzbuzz numbers.
  • Loading branch information
deadshotsb authored Oct 3, 2020
1 parent 8169ce5 commit a8bc3f2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Java/sliding_window.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/******************************************************************************
This code is developed by Sombit Bose
This program uses sliding window and modulo
opoerator for classifying fizz, buzz and fizz_buzz.
*******************************************************************************/

import java.util.*;
public class Main
{
public static void main(String[] args) {
int start_3 = 1, start_5 = 1, end_3 = 3, end_5 = 5;
Set<Integer> fizz = new HashSet<Integer>();
Set<Integer> buzz = new HashSet<Integer>();
Set<Integer> fizz_buzz = new HashSet<Integer>();
while (end_3 < 100 && end_5 < 100) {
if (end_3 == end_5)
fizz_buzz.add(end_3);
else {
fizz.add(end_3);
if (end_5 % 15 != 0)
buzz.add(end_5);
}
end_3 += 3; start_3 += 3;
if (end_3 > end_5) {
end_5 += 5; start_5 += 5;
}
}
System.out.println("The list of fizz numbers\n" + fizz);
System.out.println("The list of buzz numbers\n" + buzz);
System.out.println("The list of fizz buzz numbers\n" + fizz_buzz);
}
}

0 comments on commit a8bc3f2

Please sign in to comment.