Question: What does the following Java code do ? public static void main ( String [ ] args ) { Stack stack = new Stack <

What does the following Java code do?
public static void main(String[] args){
Stack stack = new Stack<>();
for (int i =1; i <=5; i++){
stack.push(i); }
int a =0;
while (!stack.isEmpty()){
a += stack.pop(); }
System.out.println(a); }
Prints the product of numbers from 1 to 5
a.
b. Prints the sum of even numbers from 1 to 5
c. Prints the sum of numbers from 1 to 5
d. Prints the numbers from 1 to 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!