Solution: Get Character from Alphabetical Position
Explore how to retrieve a specific alphabet character by position using Ruby arrays and zero-based indexing. Understand looping techniques like while and until loops, and practice handling user input to control program flow in interactive exercises.
We'll cover the following...
We'll cover the following...
Solution
array = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
puts "I know the alphabet very well, enter the alphabetical order number (integer) \nand I \
will tell you the corresponding letter, 0 to quit:"
while true
input = gets.chomp.to_i
if input == 0
break
end
n = input - 1
puts array[n]
endGet Alphabet from its integer position
Explanation
Line 1: We define an array of 26 elements to represent 26 ...