Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
29
Task/General-FizzBuzz/Java/general-fizzbuzz-1.java
Normal file
29
Task/General-FizzBuzz/Java/general-fizzbuzz-1.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
public class FizzBuzz {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Sound[] sounds = {new Sound(3, "Fizz"), new Sound(5, "Buzz"), new Sound(7, "Baxx")};
|
||||
for (int i = 1; i <= 20; i++) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Sound sound : sounds) {
|
||||
sb.append(sound.generate(i));
|
||||
}
|
||||
System.out.println(sb.length() == 0 ? i : sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static class Sound {
|
||||
private final int trigger;
|
||||
private final String onomatopoeia;
|
||||
|
||||
public Sound(int trigger, String onomatopoeia) {
|
||||
this.trigger = trigger;
|
||||
this.onomatopoeia = onomatopoeia;
|
||||
}
|
||||
|
||||
public String generate(int i) {
|
||||
return i % trigger == 0 ? onomatopoeia : "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue