RosettaCodeData/Task/Stack/Ballerina/stack-1.ballerina
2025-06-11 20:16:52 -04:00

15 lines
492 B
Text

import ballerina/io;
public function main() {
int[] stack = [];
stack.push(1);
stack.push(2);
io:println("Stack contains ", stack);
io:println("Number of elements in stack = ", stack.length());
int item = stack.pop();
io:println(item, " popped from the stack");
io:println("Last element is now ", stack[stack.length() - 1]);
stack.removeAll();
io:println("Stack cleared");
io:println("Is stack now empty? ", stack.length() == 0 ? "yes" : "no");
}