Created
July 1, 2020 07:11
-
-
Save mmonge/c90ed10575b95bf1c81b31a99684c34a to your computer and use it in GitHub Desktop.
Prueba para jugar con http://www.99-bottles-of-beer.net/lyrics.html
This file contains hidden or 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
import java.util.stream.IntStream; | |
import static java.lang.String.format; | |
class Sing99BottlesOfBeerOnTheWall { | |
private static final int TOTAL_BOTTLES = 100; | |
public static void main(String[] args) { | |
IntStream.rangeClosed(1, TOTAL_BOTTLES) | |
.map(i -> TOTAL_BOTTLES - i) | |
.forEach(current -> { | |
System.out.println( | |
format("%s of beer on the wall, %1$s of beer.", | |
howManyBottles(current))); | |
if (current > 0) { | |
System.out.print("take one down and pass it around, "); | |
} else { | |
System.out.print("go to the store and buy some more, "); | |
current = TOTAL_BOTTLES; | |
} | |
System.out.println( | |
format("%s of beer on the wall.\n", howManyBottles(current - 1))); | |
}); | |
System.exit(0); | |
} | |
public static String howManyBottles(int bottles) { | |
if (bottles > 1) { | |
return format("%s bottles", bottles); | |
} else if (bottles > 0) { | |
return format("%s bottle", bottles); | |
} else { | |
return format("%s bottles", "no more"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment