The source code to get the size of an array using the size() method is given below. The given program is compiled and executed successfully
# Ruby program to get the size of
# an array using size() method
arr1 = [101,"Rahul",15000];
arr2 = [101,102,103,104,105];
arr3 = Array.new(10);
print "Size of Array1: ",arr1.size(),"\n";
print "Size of Array2: ",arr2.size(),"\n";
print "Size of Array3: ",arr3.size(),"\n";
Output:
Size of Array1: 3
Size of Array2: 5
Size of Array3: 10
Explanation:
In the above program, we created 3 arrays. Then we found the size of all created arrays using the size() method and printed the result.
Program/Source Code:
The source code to get the size of an array using the size() method is given below. The given program is compiled and executed successfully
Output:
Explanation:
In the above program, we created 3 arrays. Then we found the size of all created arrays using the size() method and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer