Exploring Programming Languages — Groovy
Let’s continue our exploration of programming languages with a new, interesting one: Groovy.
Exploring Programming Languages — Groovy

Generated by Google’s Gemini
Let’s continue our exploration of programming languages with a new, interesting one: Groovy.
Not a Medium subscriber? 😕 You can read this post for free here 🥳
Groovy is kinda old language, as it’s already 23 years old. It was first published in 2003.
I heard about Groovy a long time ago, but I wasn’t a fan of Java at that time, so I never tried to learn it. Big mistake that’s for sure.
Fun fact: Groovy is a Java syntax-compatible language. So we can say that it is Java with nicer options 😉
Ok, let’s jump into our main topic, which is creating an LED Numbers application.
The application should work like this: we input 1977, and it returns:

LED Numbers output
Now, keep in mind that we want to show this to newcomers to Groovy, not to seasoned developers.
The first thing we’re going to do is create a HashMap (Similar to a Map or Dictionary in other languages) to hold all the components of the LED numbers:
def leds = ["0": " _ ,| | ,|_| ",
"1": " , | , | ",
"2": " _ , _|, |_ ",
"3": " _ , _| , _| ",
"4": " ,|_| , | ",
"5": " _ ,|_ , _| ",
"6": " _ ,|_ ,|_| ",
"7": "_ , | , | ",
"8": " _ ,|_| ,|_| ",
"9": " _ ,|_| , _| "]
We’re separating each number into three lines. So, for example, if we were to print the number 6, we could do it like this:
println leds["6"][0..3]
println leds["6"][5..8]
println leds["6"][10..13]
We’re going to read leds using index 6 and then extract the content of the first section of the value, then the second, and finally the third one.
The result is going to be:
_
|_
|_|
Of course, we would like to print more than one number, so the idea would be to concatenate each number’s line and then print them:
println leds["6"][0..3] + leds["2"][0..3]
println leds["6"][5..8] + leds["2"][5..8]
println leds["6"][10..13] + leds["2"][10..13]
The result is going to be:
_ _
|_ _|
|_| |_
Of course, we need a way to automate this, as the number gets longer, our print commands would be longer 🤨, and we don’t want anything hardcoded.
Ok, we have then 3 lines that need to be printed. But an unknown number. It’s important to know at runtime how many digits our number has so that we act accordingly. Let’s say we want to print the number 1593, so we have 4 digits, and we need to print 3 lines, each line with sections of those 4 digits, so here’s our application code:
def leds = ["0": " _ ,| | ,|_| ",
"1": " , | , | ",
"2": " _ , _|, |_ ",
"3": " _ , _| , _| ",
"4": " ,|_| , | ",
"5": " _ ,|_ , _| ",
"6": " _ ,|_ ,|_| ",
"7": "_ , | , | ",
"8": " _ ,|_| ,|_| ",
"9": " _ ,|_| , _| "]
def num = System.console().readLine 'Enter a number: '
line1 = ""
line2 = ""
line3 = ""
0.step(num.length(), 1) { digit ->
line1 += leds[num[digit]][0..3]
line2 += leds[num[digit]][5..8]
line3 += leds[num[digit]][10..13]
}
println line1
println line2
println line3
- First, we’re going to ask the user to input a number, and we will read it using System.console().readline
- We’re going to declare three variables as placeholders.
- Then, we’re going to perform a loop from 0 to the length of the input number. We’re going to add 1 to every iteration. We do this to read each digit from the input number.
- Finally, we’re going to read our led Hashmap using the proper digit and extract the value from the resulting string.
To make things easier, let’s debug our application and see which values would be present on each iteration:
- We input the number 1593, and we start the loop with i having the value of 0.
- We use 0 and read the num input using num[digit], and then we use that to read the Hashmap led[num[digit]], then we extract the values from the string that we need for each line.
|
|
We can move to the second iteration of the first loop. Where everything will be repeated with the exception that I will have the value of 2, meaning, it will read the digit 5:
_
| |_
| _|
We can move into the third iteration. Again, everything repeats, but i has a value of 3, meaning it will read the digit 9:
_ _
| |_ |_|
| _| _|
Finally, we move into the last iteration of the loop, as we’re out of digits. We’re going to use the digit 3.
_ _ _
| |_ |_| _|
| _| _| _|
And the application is over. If we name our application LEDNumbers.groovy, we can run it on the terminal window like this:
groovy LEDNumbers.groovy

That’s it 🤓 I hope you liked it. I will see you again in the next installment, which will present Amber.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Follow me on X: @Blag Follow me on BlueSky: @blag.bsky.social Connect with me on LinkedIn: Blag aka Alvaro Tejada Galindo
메타데이터
- post_id
- c7c0be92a014
- slug
- exploring-programming-languages-groovy-c7c0be92a014
- url
- https://blog.devgenius.io/exploring-programming-languages-groovy-c7c0be92a014
- canonical_url
- https://blog.devgenius.io/exploring-programming-languages-groovy-c7c0be92a014
- author_url
- https://medium.com/@atejada
- status
- ok
- fetched_at
- 2026-06-17 08:20:12