I would probably create the following methods (I have left singleUltraFizzBuzz undefined so I don't end up writing the whole thing; singleUltraFizzBuzz should do the check for the empty string):
public static abstract String singleUltraFizzBuzz(SortedMap<Integer, String> fizzBuzzes, Integerint i) {
StringBuilder result = new StringBuilder();
bool isEmpty = true;
for(Map.Entry<String, Object> entry : fizzBuzzes.entrySet()) {
if(i % entry.getKey() == 0) {
result.append(entry.getValue());
isEmpty = false;
}
}
return isEmpty ? i.toString() : result.toString();
}
public static String ultraFizzBuzz(SortedMap<Integer, String> fizzBuzzes, Integerint maxImin, int max) {
String out = "";
for(int i = 1;min; i < 100;max; i++) {
out = out + singleUltraFizzBuzz(fizzBuzzes, i) + "\n";
}
}
which would be called as follows:
SortedMap<Integer, String> fizzBuzzes = new TreeMap<>();
fizzBuzzes.put(3, "fizz");
fizzBuzzes.put(5, "buzz");
System.out.write(ultraFizzBuzz(fizzBuzzes, 1, 100));