id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

stack_secondElement


Given a Stack of integers, return the second integer from the top. If the stack does not have at least 2 numbers, return 0.

YOUR FIRST TWO LINES OF CODE MUST BE:
Stack<Integer> stack = new Stack<Integer>();
stack.addAll(list);

stack_secondElement([1, 2, 3, 4, 5]) → 4
stack_secondElement([1, 2, 3, 4]) → 3
stack_secondElement([1, 2, 3]) → 2

...Save, Compile, Run (ctrl-enter)

public int stack_secondElement(List<Integer> list) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy