ADVERTISEMENT
ADVERTISEMENT

Ruby program to get the length of an array using the length() method

Ruby Example: Write a program to get the length of an array using the length() method.
Submitted by Nidhi, on January 09, 2022

Problem Solution:

In this program, we will create 3 arrays and find the length of created arrays using the length() method.

Program/Source Code:

The source code to get the length of an array using the length() method is given below. The given program is compiled and executed successfully.

# Ruby program to get the length of 
# an array using length() method

arr1 = [101,"Rahul",15000];
arr2 = [101,102,103,104,105];
arr3 = Array.new(10);

print "Length of Array1: ",arr1.length(),"\n";
print "Length of Array2: ",arr2.length(),"\n";
print "Length of Array3: ",arr3.length(),"\n";

Output:

Length of Array1: 3
Length of Array2: 5
Length of Array3: 10

Explanation:

In the above program, we created 3 arrays. Then we found the length of all created arrays using the length() method and printed the result.

Ruby Arrays 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.