Skip to content

Instantly share code, notes, and snippets.

@rpomeroy
Created August 4, 2014 21:47
Show Gist options
  • Save rpomeroy/1cdb57dbf9acdcd2802d to your computer and use it in GitHub Desktop.
Save rpomeroy/1cdb57dbf9acdcd2802d to your computer and use it in GitHub Desktop.
FizzBuzz Java 8
package exercises;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class FizzBuzz8 {
public static void main(String[] args) {
System.out.println(IntStream.range(1, 101).boxed()
.map(FizzBuzz8::fizzBuzz)
.collect(Collectors.joining(", ")));
System.out.format("Reversing String: FooBar %s", reverse("FooBar"));
}
public static String fizzBuzz(int val) {
if(val % 15 == 0) return "FizzBuzz";
if(val % 3 == 0) return "Fizz";
if(val % 5 == 0) return "Buzz";
return String.valueOf(val);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment