Created
August 4, 2014 21:47
-
-
Save rpomeroy/1cdb57dbf9acdcd2802d to your computer and use it in GitHub Desktop.
FizzBuzz Java 8
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
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