The source code to check an array is empty or not is given below. The given program is compiled and executed successfully.
# Ruby program to check an array is
# empty or not
arr1 = [10,21,30,nil,41,nil,50];
arr2 = [nil];
arr3 = [];
if arr1.empty?()
print "Array arr1 is an empty array.\n";
else
print "Array arr1 is not an empty array.\n";
end
if arr2.empty?()
print "Array arr2 is an empty array.\n";
else
print "Array arr2 is not an empty array.\n";
end
if arr3.empty?()
print "Array arr3 is an empty array.\n";
else
print "Array arr3 is not an empty array.\n";
end
Output:
Array arr1 is not an empty array.
Array arr2 is not an empty array.
Array arr3 is an empty array.
Explanation:
In the above program, we created 3 arrays arr1, arr2, arr3. Then we checked created arrays are empty or not using empty?() method and printed the appropriate message.
Program/Source Code:
The source code to check an array is empty or not is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created 3 arrays arr1, arr2, arr3. Then we checked created arrays are empty or not using empty?() method and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer