This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #472 from deadshotsb/master
Implementation of Sliding window in java
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |