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

 

orion.a.smith@gmail.com apcsa-lists > apcsaListHalfBeforeZeros
prev  |  next  |  chance

Given an ArrayList of Integers, replace the element just before an element with a value of zero with an element that is one-half the original value (using integer division). Return the modified ArrayList.


Precondition: elements with values of zero will have index values > 0.
HINT
Watch for bounds errors!

apcsaListHalfBeforeZeros([2, 0, 5]) → [1, 0, 5]
apcsaListHalfBeforeZeros([5, 0, 3, 2, 0]) → [2, 0, 3, 1, 0]
apcsaListHalfBeforeZeros([2, 32, 33, 0]) → [2, 32, 16, 0]

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

public ArrayList<Integer> apcsaListHalfBeforeZeros(ArrayList<Integer> lst) { }

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

Difficulty: 220

Copyright Nick Parlante 2017 - privacy