FizzBuzz/Java: Difference between revisions

→‎Recursive: newline for readable output
imported>Er2
mNo edit summary
imported>Er2
(→‎Recursive: newline for readable output)
 
(2 intermediate revisions by the same user not shown)
Line 59:
if (s.equals(""))
s = n + "";
return fizzBuzz(n-1) + "\n" + s;
}
</syntaxhighlight>
Line 92:
public static void main( String [] args ) {
int [] x = new int [100];
Arrays.setAll(x, j -> j++);
Arrays.stream(x).forEach(i -> {
if(i == 0) return;
Line 179:
 
 
=== Enum-based Declarative ===
 
With Functional and OO elements
 
A new rule can be added by adding a single line.
 
<syntaxhighlight lang="java">
Line 208 ⟶ 210:
}
 
private static String print(int i) {
String byRules = Arrays.stream(values())
.map(rule -> rule.applyRule(i))
.reducecollect("", String::concatCollectors.joining());
returnif (byRules.isEmpty() ? String.valueOf(i) : byRules;
return i + "";
return byRules;
}
 
Anonymous user