ADVERTISEMENT
ADVERTISEMENT

Ruby program to check the input string contains numbers or letters using case statement

Ruby Example: Write a program to check the input string contains numbers or letters using case statement.
Submitted by Nidhi, on December 17, 2021

Problem Solution:

In this program, we will read a string from the user and check the input string containing numbers or letters using the case statement.

Program/Source Code:

The source code to check input string containing numbers or letters using the case statement is given below. The given program is compiled and executed successfully.

# Ruby program to check the input string contains 
# numbers or letters using case statement

print "Enter string: ";
str = gets.chomp;  

puts case 
when str.match(/\d/)
    "Input string contains numbers";    
when str.match(/[a-zA-Z]/)
    "Input string contains letters";    
else
    "Invalid choice";    
end

Output:

Enter string: 1234
Input string contains numbers

Explanation:

In the above program, we read a string from the user and check the input string contains numbers or letters using the case statement, and print the appropriate message.

Ruby case Statement Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.